Fix error E0373 documentation

This commit is contained in:
1000teslas 2021-01-14 17:15:04 +11:00
parent a9ead34371
commit 174135fb3b
2 changed files with 24 additions and 8 deletions

View File

@ -54,19 +54,35 @@ about safety.
This error may also be encountered while using `async` blocks:
```compile_fail,E0373
use std::sync::Arc;
use tokio::runtime::Runtime; // 0.3.1
use std::{sync::Arc, future::Future, pin::Pin, task::{Context, Poll}};
async fn f() {
let room_ref = Arc::new(Vec::new());
let v = Arc::new(Vec::new());
let gameloop_handle = Runtime::new().unwrap().spawn(async {
game_loop(Arc::clone(&room_ref))
let handle = spawn(async { //~ ERROR E0373
g(Arc::clone(&v))
});
gameloop_handle.await;
handle.await;
}
fn game_loop(v: Arc<Vec<usize>>) {}
fn g(v: Arc<Vec<usize>>) {}
fn spawn<F>(future: F) -> JoinHandle
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
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

View File

@ -1,6 +1,6 @@
// edition:2018
use std::{sync::Arc, future::Future, pin::Pin, task::{Context,Poll}};
use std::{sync::Arc, future::Future, pin::Pin, task::{Context, Poll}};
async fn f() {
let room_ref = Arc::new(Vec::new());