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:
commit
af5b0d9883
4 changed files with 89 additions and 5 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue