Skip to content

Commit dd2356f

Browse files
committed
add testcase for generator move suggestion
1 parent 0221e26 commit dd2356f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// edition:2018
2+
#![feature(async_closure,async_await)]
3+
fn foo() -> Box<impl std::future::Future<Output = u32>> {
4+
let x = 0u32;
5+
Box::new(async { x } )
6+
//~^ ERROR E0373
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
2+
--> $DIR/async-borrowck-escaping-block-error.rs:5:20
3+
|
4+
LL | Box::new(async { x } )
5+
| ^^-^^
6+
| | |
7+
| | `x` is borrowed here
8+
| may outlive borrowed value `x`
9+
|
10+
note: generator is returned here
11+
--> $DIR/async-borrowck-escaping-block-error.rs:3:13
12+
|
13+
LL | fn foo() -> Box<impl std::future::Future<Output = u32>> {
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
16+
|
17+
LL | Box::new(async move { x } )
18+
| ^^^^^^^^^^
19+
20+
error: aborting due to previous error
21+
22+
For more information about this error, try `rustc --explain E0373`.

0 commit comments

Comments
 (0)