1
Fork 0

Force move async-closures that are FnOnce to make their inner coroutines also move

This commit is contained in:
Michael Goulet 2024-04-03 12:16:17 -04:00
parent 3d9d5d7c96
commit 55e46612c1
7 changed files with 57 additions and 73 deletions

View file

@ -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;
}

View file

@ -8,3 +8,7 @@ Hello(3)
Hello(4)
Hello(4)
Hello(5)
Hello(6)
Hello(7)
Hello(8)
Hello(9)

View file

@ -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`.