Force move
async-closures that are FnOnce
to make their inner coroutines also move
This commit is contained in:
parent
3d9d5d7c96
commit
55e46612c1
7 changed files with 57 additions and 73 deletions
|
@ -1,7 +1,7 @@
|
|||
//@ aux-build:block-on.rs
|
||||
//@ edition:2021
|
||||
|
||||
|
||||
//@ run-pass
|
||||
//@ check-run-results
|
||||
|
||||
// Same as miri's `tests/pass/async-closure-captures.rs`, keep in sync
|
||||
|
||||
|
@ -104,14 +104,12 @@ async fn async_main() {
|
|||
let x = Hello(8);
|
||||
let c = force_fnonce(async || {
|
||||
println!("{x:?}");
|
||||
//~^ ERROR `x` does not live long enough
|
||||
});
|
||||
call_once(c).await;
|
||||
|
||||
let x = &Hello(9);
|
||||
let c = force_fnonce(async || {
|
||||
println!("{x:?}");
|
||||
//~^ ERROR `x` does not live long enough
|
||||
});
|
||||
call_once(c).await;
|
||||
}
|
||||
|
|
|
@ -8,3 +8,7 @@ Hello(3)
|
|||
Hello(4)
|
||||
Hello(4)
|
||||
Hello(5)
|
||||
Hello(6)
|
||||
Hello(7)
|
||||
Hello(8)
|
||||
Hello(9)
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/captures.rs:89:24
|
||||
|
|
||||
LL | let c = force_fnonce(async move || {
|
||||
| ____________________________________________-
|
||||
LL | | println!("{x:?}");
|
||||
| | ^ borrowed value does not live long enough
|
||||
LL | | });
|
||||
| | --
|
||||
| | ||
|
||||
| | |`x` dropped here while still borrowed
|
||||
| |_________|borrow later used here
|
||||
| value captured here by coroutine
|
||||
|
||||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/captures.rs:95:24
|
||||
|
|
||||
LL | let c = force_fnonce(async move || {
|
||||
| ____________________________________________-
|
||||
LL | | println!("{x:?}");
|
||||
| | ^ borrowed value does not live long enough
|
||||
LL | | });
|
||||
| | --
|
||||
| | ||
|
||||
| | |`x` dropped here while still borrowed
|
||||
| |_________|borrow later used here
|
||||
| value captured here by coroutine
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0597`.
|
Loading…
Add table
Add a link
Reference in a new issue