1
Fork 0

Rollup merge of #80614 - 1000teslas:issue-78938-fix, r=tmandry

Explain why borrows can't be held across yield point in async blocks

For https://github.com/rust-lang/rust/issues/78938.
This commit is contained in:
Mara Bos 2021-01-16 17:29:49 +00:00 committed by GitHub
commit af5b0d9883
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 89 additions and 5 deletions

View file

@ -50,3 +50,24 @@ fn foo() -> Box<Fn(u32) -> u32> {
Now that the closure has its own copy of the data, there's no need to worry
about safety.
This error may also be encountered while using `async` blocks:
```compile_fail,E0373,edition2018
use std::future::Future;
async fn f() {
let v = vec![1, 2, 3i32];
spawn(async { //~ ERROR E0373
println!("{:?}", v)
});
}
fn spawn<F: Future + Send + 'static>(future: F) {
unimplemented!()
}
```
Similarly to closures, `async` blocks are not executed immediately and may
capture closed-over data by reference. For more information, see
https://rust-lang.github.io/async-book/03_async_await/01_chapter.html.