Simplify E0373 async code example
This commit is contained in:
parent
63deae5e25
commit
5468d9805a
@ -54,35 +54,18 @@ about safety.
|
|||||||
This error may also be encountered while using `async` blocks:
|
This error may also be encountered while using `async` blocks:
|
||||||
|
|
||||||
```compile_fail,E0373,edition2018
|
```compile_fail,E0373,edition2018
|
||||||
use std::{sync::Arc, future::Future, pin::Pin, task::{Context, Poll}};
|
use std::future::Future;
|
||||||
|
|
||||||
async fn f() {
|
async fn f() {
|
||||||
let v = Arc::new(Vec::new());
|
let v = vec![1, 2, 3i32];
|
||||||
|
spawn(async { //~ ERROR E0373
|
||||||
let handle = spawn(async { //~ ERROR E0373
|
println!("{:?}", v)
|
||||||
g(Arc::clone(&v))
|
|
||||||
});
|
});
|
||||||
handle.await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn g(v: Arc<Vec<usize>>) {}
|
fn spawn<F: Future + Send + 'static>(future: F) {
|
||||||
|
|
||||||
fn spawn<F>(future: F) -> JoinHandle
|
|
||||||
where
|
|
||||||
F: Future + Send + 'static,
|
|
||||||
F::Output: Send + 'static,
|
|
||||||
{
|
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
struct JoinHandle;
|
|
||||||
|
|
||||||
impl Future for JoinHandle {
|
|
||||||
type Output = ();
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Similarly to closures, `async` blocks are not executed immediately and may
|
Similarly to closures, `async` blocks are not executed immediately and may
|
||||||
|
Loading…
Reference in New Issue
Block a user