forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#63699 - gilescope:async-move-diagnostic, r=…
…estebank Fix suggestion from incorrect `move async` to `async move`. PR for rust-lang#61920. Happy with the test. There must be a better implementation though - possibly a MIR visitor to estabilsh a span that doesn't include the `async` keyword?
- Loading branch information
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/test/ui/async-await/async-borrowck-escaping-closure-error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// edition:2018 | ||
#![feature(async_closure,async_await)] | ||
fn foo() -> Box<dyn std::future::Future<Output = u32>> { | ||
let x = 0u32; | ||
Box::new((async || x)()) | ||
//~^ ERROR E0373 | ||
} | ||
|
||
fn main() { | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/async-await/async-borrowck-escaping-closure-error.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function | ||
--> $DIR/async-borrowck-escaping-closure-error.rs:5:15 | ||
| | ||
LL | Box::new((async || x)()) | ||
| ^^^^^^^^ - `x` is borrowed here | ||
| | | ||
| may outlive borrowed value `x` | ||
| | ||
note: closure is returned here | ||
--> $DIR/async-borrowck-escaping-closure-error.rs:5:5 | ||
| | ||
LL | Box::new((async || x)()) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword | ||
| | ||
LL | Box::new((async move || x)()) | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0373`. |