Coder Social home page Coder Social logo

scoped-tls-hkt's People

Contributors

diggsey avatar ogoffart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

scoped-tls-hkt's Issues

Soundness hole in mutable HKT thread-local: Sufficiently general `ReborrowMut` implementation is not properly enforced.

use scoped_tls_hkt::{scoped_thread_local, ReborrowMut};
use std::sync::OnceLock;

static STR_HOLDER: OnceLock<&str> = OnceLock::new();
struct S<'a>(&'a str);
impl<'a> ReborrowMut<'a> for S<'static> {
    type Result = S<'a>;

    fn reborrow_mut(&'a mut self) -> Self::Result {
        STR_HOLDER.set(self.0).unwrap();
        S("")
    }
}

fn main() {
    scoped_thread_local!(static mut STRING: for<'a> S<'a>);
    let string = String::from("Hello World");
    STRING.set(S(&string), || STRING.with(|_| ()));

    let hello: &str = STR_HOLDER.get().unwrap();
    println!("now it exists: {hello}");
    drop(string);
    println!("now it's gone: {hello}");
}
now it exists: Hello World
now it's gone: >�e�3~

The relevant code is

// This wrapper helps to ensure that the 'static lifetime is not visible
// to the safe code.
fn cast_from_static<'a, 'b>(x: &'a mut Hkt<'static>) -> Hkt<'b> where 'a: 'b {
    ReborrowMut::reborrow_mut(x)
}

This only enforces a ReborrowMut implementation to be present for Hkt<'static>.
It thus does not do as promised, and it does expose the 'static lifetime to safe user code.

Probably can be fixed by making cast_from_static more generic… a change like this might be sufficient (though I haven’t tested it):

// This wrapper helps to ensure that the 'static lifetime is not visible
// to the safe code.
fn cast_from_static<'a, 'b>(x: &'a mut Hkt<'_>) -> Hkt<'b> where 'a: 'b {
    ReborrowMut::reborrow_mut(x)
}

Edit: I’ve tested it now, this change should be sufficient.

Multiple tests fail on Fedora

I am packaging scoped-tls-hkt for Fedora and we run cargo test as part of all builds and I see many failures:

failures:

---- src/chan.rs - chan::Receiver<T>::capacity (line 326) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:327:5
  |
3 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
 --> src/chan.rs:329:14
  |
5 | let (_, r) = channel::<i32>(5);
  |              ^^^^^^^ not found in this scope
  |
help: possible candidates are found in other modules, you can import them into scope
  |
2 | use futures::channel::mpsc::channel;
  |
2 | use futures::channel::oneshot::channel;
  |
2 | use std::sync::mpsc::channel;
  |

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0425, E0433.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/chan.rs - chan::Receiver<T>::is_full (line 365) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:368:5
  |
5 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:366:1
  |
3 | async_std::task::block_on(async {
  | ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
 --> src/chan.rs:370:14
  |
7 | let (s, r) = channel(1);
  |              ^^^^^^^ not found in this scope
  |
help: possible candidates are found in other modules, you can import them into scope
  |
2 | use futures::channel::mpsc::channel;
  |
2 | use futures::channel::oneshot::channel;
  |
2 | use std::sync::mpsc::channel;
  |

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:373:8
   |
10 | s.send(0).await;
   |        ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:373:1
   |
10 | s.send(0).await;
   | ^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0425, E0433, E0698.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/arc.rs - arc::Arc<T>::new (line 45) stdout ----
error[E0423]: expected function, tuple struct or tuple variant, found struct `Arc`
 --> src/arc.rs:51:9
  |
9 | let a = Arc(sync::Arc::new(7));
  |         ^^^ did you mean `Arc { /* fields */ }`?

error: aborting due to previous error

For more information about this error, try `rustc --explain E0423`.
Couldn't compile the test.
---- src/chan.rs - chan::Receiver<T>::recv (line 299) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:302:5
  |
5 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0432]: unresolved import `async_std`
 --> src/chan.rs:303:5
  |
6 | use async_std::task;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:300:1
  |
3 | async_std::task::block_on(async {
  | ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
 --> src/chan.rs:305:14
  |
8 | let (s, r) = channel(1);
  |              ^^^^^^^ not found in this scope
  |
help: possible candidates are found in other modules, you can import them into scope
  |
2 | use futures::channel::mpsc::channel;
  |
2 | use futures::channel::oneshot::channel;
  |
2 | use std::sync::mpsc::channel;
  |

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:308:12
   |
11 |     s.send(1).await;
   |            ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:308:5
   |
11 |     s.send(1).await;
   |     ^^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:309:12
   |
12 |     s.send(2).await;
   |            ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:309:5
   |
12 |     s.send(2).await;
   |     ^^^^^^^^^^^^^^^

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0425, E0432, E0433, E0698.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/chan.rs - chan::Receiver<T>::is_empty (line 344) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:347:5
  |
5 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:345:1
  |
3 | async_std::task::block_on(async {
  | ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
 --> src/chan.rs:349:14
  |
7 | let (s, r) = channel(1);
  |              ^^^^^^^ not found in this scope
  |
help: possible candidates are found in other modules, you can import them into scope
  |
2 | use futures::channel::mpsc::channel;
  |
2 | use futures::channel::oneshot::channel;
  |
2 | use std::sync::mpsc::channel;
  |

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:352:8
   |
10 | s.send(0).await;
   |        ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:352:1
   |
10 | s.send(0).await;
   | ^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0425, E0433, E0698.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/chan.rs - chan::Receiver<T>::len (line 386) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:389:5
  |
5 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:387:1
  |
3 | async_std::task::block_on(async {
  | ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
 --> src/chan.rs:391:14
  |
7 | let (s, r) = channel(2);
  |              ^^^^^^^ not found in this scope
  |
help: possible candidates are found in other modules, you can import them into scope
  |
2 | use futures::channel::mpsc::channel;
  |
2 | use futures::channel::oneshot::channel;
  |
2 | use std::sync::mpsc::channel;
  |

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:394:8
   |
10 | s.send(1).await;
   |        ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:394:1
   |
10 | s.send(1).await;
   | ^^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:395:8
   |
11 | s.send(2).await;
   |        ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:395:1
   |
11 | s.send(2).await;
   | ^^^^^^^^^^^^^^^

error: aborting due to 5 previous errors

Some errors have detailed explanations: E0425, E0433, E0698.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/chan.rs - chan::Receiver (line 257) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:262:5
  |
7 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0432]: unresolved import `async_std`
 --> src/chan.rs:263:5
  |
8 | use async_std::task;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:258:1
  |
3 | async_std::task::block_on(async {
  | ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
  --> src/chan.rs:265:14
   |
10 | let (s, r) = channel(100);
   |              ^^^^^^^ not found in this scope
   |
help: possible candidates are found in other modules, you can import them into scope
   |
2  | use futures::channel::mpsc::channel;
   |
2  | use futures::channel::oneshot::channel;
   |
2  | use std::sync::mpsc::channel;
   |

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:268:12
   |
13 |     s.send(1).await;
   |            ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:268:5
   |
13 |     s.send(1).await;
   |     ^^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:270:12
   |
15 |     s.send(2).await;
   |            ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:270:5
   |
15 |     s.send(2).await;
   |     ^^^^^^^^^^^^^^^

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0425, E0432, E0433, E0698.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/arc.rs - arc::Arc (line 18) stdout ----
error[E0432]: unresolved import `smol`
 --> src/arc.rs:21:5
  |
5 | use smol::Async;
  |     ^^^^ use of undeclared type or module `smol`

error[E0433]: failed to resolve: use of undeclared type or module `smol`
 --> src/arc.rs:24:36
  |
8 | fn main() -> std::io::Result<()> { smol::run(async {
  |                                    ^^^^ use of undeclared type or module `smol`

error[E0599]: no method named `clone` found for struct `piper::Arc<_>` in the current scope
  --> src/arc.rs:30:25
   |
14 | let mut writer = reader.clone();
   |                         ^^^^^ method not found in `piper::Arc<_>`
   |
   = note: `reader` is a function, perhaps you wish to call it

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0432, E0433, E0599.
For more information about an error, try `rustc --explain E0432`.
Couldn't compile the test.
---- src/chan.rs - chan::Sender<T>::capacity (line 137) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:138:5
  |
3 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
 --> src/chan.rs:140:14
  |
5 | let (s, _) = channel::<i32>(5);
  |              ^^^^^^^ not found in this scope
  |
help: possible candidates are found in other modules, you can import them into scope
  |
2 | use futures::channel::mpsc::channel;
  |
2 | use futures::channel::oneshot::channel;
  |
2 | use std::sync::mpsc::channel;
  |

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0425, E0433.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/chan.rs - chan::Sender<T>::len (line 197) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:200:5
  |
5 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:198:1
  |
3 | async_std::task::block_on(async {
  | ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
 --> src/chan.rs:202:14
  |
7 | let (s, r) = channel(2);
  |              ^^^^^^^ not found in this scope
  |
help: possible candidates are found in other modules, you can import them into scope
  |
2 | use futures::channel::mpsc::channel;
  |
2 | use futures::channel::oneshot::channel;
  |
2 | use std::sync::mpsc::channel;
  |

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:205:8
   |
10 | s.send(1).await;
   |        ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:205:1
   |
10 | s.send(1).await;
   | ^^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:206:8
   |
11 | s.send(2).await;
   |        ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:206:1
   |
11 | s.send(2).await;
   | ^^^^^^^^^^^^^^^

error: aborting due to 5 previous errors

Some errors have detailed explanations: E0425, E0433, E0698.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/chan.rs - chan::Sender (line 79) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:82:5
  |
5 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0432]: unresolved import `async_std`
 --> src/chan.rs:83:5
  |
6 | use async_std::task;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:80:1
  |
3 | async_std::task::block_on(async {
  | ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
 --> src/chan.rs:85:15
  |
8 | let (s1, r) = channel(100);
  |               ^^^^^^^ not found in this scope
  |
help: possible candidates are found in other modules, you can import them into scope
  |
2 | use futures::channel::mpsc::channel;
  |
2 | use futures::channel::oneshot::channel;
  |
2 | use std::sync::mpsc::channel;
  |

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:88:34
   |
11 | task::spawn(async move { s1.send(1).await });
   |                                  ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:88:26
   |
11 | task::spawn(async move { s1.send(1).await });
   |                          ^^^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:89:34
   |
12 | task::spawn(async move { s2.send(2).await });
   |                                  ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:89:26
   |
12 | task::spawn(async move { s2.send(2).await });
   |                          ^^^^^^^^^^^^^^^^

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0425, E0432, E0433, E0698.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/chan.rs - chan::Sender<T>::is_full (line 176) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:179:5
  |
5 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:177:1
  |
3 | async_std::task::block_on(async {
  | ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
 --> src/chan.rs:181:14
  |
7 | let (s, r) = channel(1);
  |              ^^^^^^^ not found in this scope
  |
help: possible candidates are found in other modules, you can import them into scope
  |
2 | use futures::channel::mpsc::channel;
  |
2 | use futures::channel::oneshot::channel;
  |
2 | use std::sync::mpsc::channel;
  |

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:184:8
   |
10 | s.send(0).await;
   |        ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:184:1
   |
10 | s.send(0).await;
   | ^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0425, E0433, E0698.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/chan.rs - chan::Sender<T>::is_empty (line 155) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:158:5
  |
5 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:156:1
  |
3 | async_std::task::block_on(async {
  | ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
 --> src/chan.rs:160:14
  |
7 | let (s, r) = channel(1);
  |              ^^^^^^^ not found in this scope
  |
help: possible candidates are found in other modules, you can import them into scope
  |
2 | use futures::channel::mpsc::channel;
  |
2 | use futures::channel::oneshot::channel;
  |
2 | use std::sync::mpsc::channel;
  |

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:163:8
   |
10 | s.send(0).await;
   |        ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:163:1
   |
10 | s.send(0).await;
   | ^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0425, E0433, E0698.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/chan.rs - chan::chan (line 34) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:39:5
  |
7 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0432]: unresolved import `async_std`
 --> src/chan.rs:40:5
  |
8 | use async_std::task;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:35:1
  |
3 | async_std::task::block_on(async {
  | ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
  --> src/chan.rs:42:14
   |
10 | let (s, r) = channel(1);
   |              ^^^^^^^ not found in this scope
   |
help: possible candidates are found in other modules, you can import them into scope
   |
2  | use futures::channel::mpsc::channel;
   |
2  | use futures::channel::oneshot::channel;
   |
2  | use std::sync::mpsc::channel;
   |

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:50:12
   |
18 |     s.send(2).await;
   |            ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:50:5
   |
18 |     s.send(2).await;
   |     ^^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:45:8
   |
13 | s.send(1).await;
   |        ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:45:1
   |
13 | s.send(1).await;
   | ^^^^^^^^^^^^^^^

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0425, E0432, E0433, E0698.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/chan.rs - chan::Sender<T>::send (line 110) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:113:5
  |
5 | use async_std::sync::channel;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0432]: unresolved import `async_std`
 --> src/chan.rs:114:5
  |
6 | use async_std::task;
  |     ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0433]: failed to resolve: use of undeclared type or module `async_std`
 --> src/chan.rs:111:1
  |
3 | async_std::task::block_on(async {
  | ^^^^^^^^^ use of undeclared type or module `async_std`

error[E0425]: cannot find function `channel` in this scope
 --> src/chan.rs:116:14
  |
8 | let (s, r) = channel(1);
  |              ^^^^^^^ not found in this scope
  |
help: possible candidates are found in other modules, you can import them into scope
  |
2 | use futures::channel::mpsc::channel;
  |
2 | use futures::channel::oneshot::channel;
  |
2 | use std::sync::mpsc::channel;
  |

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:119:12
   |
11 |     s.send(1).await;
   |            ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:119:5
   |
11 |     s.send(1).await;
   |     ^^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/chan.rs:120:12
   |
12 |     s.send(2).await;
   |            ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/chan.rs:120:5
   |
12 |     s.send(2).await;
   |     ^^^^^^^^^^^^^^^

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0425, E0432, E0433, E0698.
For more information about an error, try `rustc --explain E0425`.
Couldn't compile the test.
---- src/lock.rs - lock::Lock (line 15) stdout ----
error[E0432]: unresolved import `smol`
 --> src/lock.rs:19:5
  |
7 | use smol::Task;
  |     ^^^^ use of undeclared type or module `smol`

error[E0433]: failed to resolve: use of undeclared type or module `smol`
 --> src/lock.rs:16:1
  |
4 | smol::run(async {
  | ^^^^ use of undeclared type or module `smol`

error[E0698]: type inside `async` block must be known in this context
  --> src/lock.rs:28:28
   |
16 |         *l.lock().await += 1;
   |                            ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/lock.rs:28:10
   |
16 |         *l.lock().await += 1;
   |          ^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/lock.rs:28:10
   |
16 |         *l.lock().await += 1;
   |          ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/lock.rs:28:10
   |
16 |         *l.lock().await += 1;
   |          ^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/lock.rs:28:10
   |
16 |         *l.lock().await += 1;
   |          ^^^^^^^^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/lock.rs:28:10
   |
16 |         *l.lock().await += 1;
   |          ^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/lock.rs:28:10
   |
16 |         *l.lock().await += 1;
   |          ^^^^^^^^^^^^^^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/lock.rs:28:10
   |
16 |         *l.lock().await += 1;
   |          ^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/lock.rs:22:5
   |
10 | let l = Arc::new(Lock::new(0));
   |     ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/lock.rs:35:13
   |
23 | assert_eq!(*l.lock().await, 10);
   |             ^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/lock.rs:35:13
   |
23 | assert_eq!(*l.lock().await, 10);
   |             ^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/lock.rs:35:13
   |
23 | assert_eq!(*l.lock().await, 10);
   |             ^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/lock.rs:35:13
   |
23 | assert_eq!(*l.lock().await, 10);
   |             ^^^^^^^^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/lock.rs:35:13
   |
23 | assert_eq!(*l.lock().await, 10);
   |             ^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
  --> src/lock.rs:35:13
   |
23 | assert_eq!(*l.lock().await, 10);
   |             ^^^^^^^^^^^^^^ cannot infer type for type `{integer}`
   |
note: the type is part of the `async` block because of this `await`
  --> src/lock.rs:35:13
   |
23 | assert_eq!(*l.lock().await, 10);
   |             ^^^^^^^^^^^^^^

error: aborting due to 10 previous errors

Some errors have detailed explanations: E0432, E0433, E0698.
For more information about an error, try `rustc --explain E0432`.
Couldn't compile the test.
---- src/lock.rs - lock::Lock<T>::lock (line 80) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `smol`
 --> src/lock.rs:81:1
  |
4 | smol::block_on(async {
  | ^^^^ use of undeclared type or module `smol`

error[E0698]: type inside `async` block must be known in this context
 --> src/lock.rs:85:5
  |
8 | let l = Lock::new(10);
  |     ^ cannot infer type for type `{integer}`
  |
note: the type is part of the `async` block because of this `await`
 --> src/lock.rs:86:13
  |
9 | let guard = l.lock().await;
  |             ^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
 --> src/lock.rs:86:13
  |
9 | let guard = l.lock().await;
  |             ^ cannot infer type for type `{integer}`
  |
note: the type is part of the `async` block because of this `await`
 --> src/lock.rs:86:13
  |
9 | let guard = l.lock().await;
  |             ^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
 --> src/lock.rs:86:13
  |
9 | let guard = l.lock().await;
  |             ^^^^^^^^ cannot infer type for type `{integer}`
  |
note: the type is part of the `async` block because of this `await`
 --> src/lock.rs:86:13
  |
9 | let guard = l.lock().await;
  |             ^^^^^^^^^^^^^^

error[E0698]: type inside `async` block must be known in this context
 --> src/lock.rs:86:13
  |
9 | let guard = l.lock().await;
  |             ^^^^^^^^^^^^^^ cannot infer type for type `{integer}`
  |
note: the type is part of the `async` block because of this `await`
 --> src/lock.rs:86:13
  |
9 | let guard = l.lock().await;
  |             ^^^^^^^^^^^^^^

error: aborting due to 5 previous errors

Some errors have detailed explanations: E0433, E0698.
For more information about an error, try `rustc --explain E0433`.
Couldn't compile the test.
---- src/lock.rs - lock::Lock<T>::try_lock (line 116) stdout ----
error[E0308]: mismatched types
 --> src/lock.rs:120:8
  |
7 | if let Ok(guard) = l.try_lock() {
  |        ^^^^^^^^^   ------------ this expression has type `std::option::Option<piper::LockGuard<{integer}>>`
  |        |
  |        expected enum `std::option::Option`, found enum `std::result::Result`
  |
  = note: expected enum `std::option::Option<piper::LockGuard<{integer}>>`
             found enum `std::result::Result<_, _>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
Couldn't compile the test.
---- src/mutex.rs - mutex::Mutex<T>::try_lock (line 121) stdout ----
error[E0308]: mismatched types
 --> src/mutex.rs:125:8
  |
7 | if let Ok(guard) = mutex.try_lock() {
  |        ^^^^^^^^^   ---------------- this expression has type `std::option::Option<piper::MutexGuard<'_, {integer}>>`
  |        |
  |        expected enum `std::option::Option`, found enum `std::result::Result`
  |
  = note: expected enum `std::option::Option<piper::MutexGuard<'_, {integer}>>`
             found enum `std::result::Result<_, _>`

error: aborting due to previous error

Do you know what might be a problem? Am I doing something wrong?

Nightly rust warning: cross-crate traits with a default impl, like `Sync`, should not be specialized

Using the macro result in a warning with rust nightly:

For example, running cargo test in this crate result in many warning. First one:

error: cross-crate traits with a default impl, like `Sync`, should not be specialized
   --> src/lib.rs:233:17
    |
233 |                 unsafe impl Sync for $name<'static> {}
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
731 |         scoped_thread_local!(static BAR: for<'a> Foo<'a>);
    |         ------------------------------------------------- in this macro invocation
    |
note: the lint level is defined here
   --> src/lib.rs:136:23
    |
136 | #![deny(missing_docs, warnings)]
    |                       ^^^^^^^^
    = note: `#[deny(suspicious_auto_trait_impls)]` implied by `#[deny(warnings)]`
    = warning: this will change its meaning in a future release!
    = note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
note: try using the same sequence of generic parameters as the struct definition
   --> src/lib.rs:215:9
    |
215 | /         $vis struct $name<$lt> where ::std::cell::Cell<::std::option::Option<$ty>>: 'static {
216 | |             inner: &$lt ::std::thread::LocalKey<::std::cell::Cell<::std::option::Option<$ty>>>,
217 | |         }
    | |_________^
...
731 |           scoped_thread_local!(static BAR: for<'a> Foo<'a>);
    |           ------------------------------------------------- in this macro invocation
    = note: `'static` is not a generic parameter
    = note: this error originates in the macro `scoped_thread_local` (in Nightly builds, run with -Z macro-backtrace for more info)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.