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#65166 - csmoe:async-move, r=estebank
Suggest to add `move` keyword for generator capture Closes rust-lang#64382 r? @estebank
- Loading branch information
Showing
5 changed files
with
74 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
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
12 changes: 12 additions & 0 deletions
12
src/test/ui/async-await/async-borrowck-escaping-block-error.fixed
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,12 @@ | ||
// edition:2018 | ||
// run-rustfix | ||
|
||
fn foo() -> Box<impl std::future::Future<Output = u32>> { | ||
let x = 0u32; | ||
Box::new(async move { x } ) | ||
//~^ ERROR E0373 | ||
} | ||
|
||
fn main() { | ||
let _foo = foo(); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/ui/async-await/async-borrowck-escaping-block-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,12 @@ | ||
// edition:2018 | ||
// run-rustfix | ||
|
||
fn foo() -> Box<impl std::future::Future<Output = u32>> { | ||
let x = 0u32; | ||
Box::new(async { x } ) | ||
//~^ ERROR E0373 | ||
} | ||
|
||
fn main() { | ||
let _foo = foo(); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/ui/async-await/async-borrowck-escaping-block-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,22 @@ | ||
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function | ||
--> $DIR/async-borrowck-escaping-block-error.rs:6:20 | ||
| | ||
LL | Box::new(async { x } ) | ||
| ^^-^^ | ||
| | | | ||
| | `x` is borrowed here | ||
| may outlive borrowed value `x` | ||
| | ||
note: generator is returned here | ||
--> $DIR/async-borrowck-escaping-block-error.rs:4:13 | ||
| | ||
LL | fn foo() -> Box<impl std::future::Future<Output = u32>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
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`. |