forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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#123518 - compiler-errors:by-move-fixes, r=oli-obk Fix `ByMove` coroutine-closure shim (for 2021 precise closure capturing behavior) This PR reworks the way that we perform the `ByMove` coroutine-closure shim to account for the fact that the upvars of the outer coroutine-closure and the inner coroutine might not line up due to edition-2021 closure capture rules changes. Specifically, the number of upvars may differ *and/or* the inner coroutine may have additional projections applied to an upvar. This PR reworks the information we pass into the `ByMoveBody` MIR visitor to account for both of these facts. I tried to leave comments explaining exactly what everything is doing, but let me know if you have questions. r? oli-obk
- Loading branch information
Showing
8 changed files
with
461 additions
and
35 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//@ aux-build:block-on.rs | ||
//@ run-pass | ||
//@ check-run-results | ||
//@ revisions: e2021 e2018 | ||
//@[e2018] edition:2018 | ||
//@[e2021] edition:2021 | ||
|
||
#![feature(async_closure)] | ||
|
||
extern crate block_on; | ||
|
||
async fn call_once(f: impl async FnOnce()) { f().await; } | ||
|
||
pub async fn async_closure(x: &mut i32) { | ||
let c = async move || { | ||
*x += 1; | ||
}; | ||
call_once(c).await; | ||
} | ||
|
||
fn main() { | ||
block_on::block_on(async { | ||
let mut x = 0; | ||
async_closure(&mut x).await; | ||
assert_eq!(x, 1); | ||
}); | ||
} |
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,27 @@ | ||
//@ aux-build:block-on.rs | ||
//@ edition:2021 | ||
//@ run-pass | ||
//@ check-run-results | ||
|
||
#![feature(async_closure)] | ||
|
||
extern crate block_on; | ||
|
||
async fn call_once(f: impl async FnOnce()) { | ||
f().await; | ||
} | ||
|
||
async fn async_main() { | ||
let x = &mut 0; | ||
let y = &mut 0; | ||
let c = async || { | ||
*x = 1; | ||
*y = 2; | ||
}; | ||
call_once(c).await; | ||
println!("{x} {y}"); | ||
} | ||
|
||
fn main() { | ||
block_on::block_on(async_main()); | ||
} |
1 change: 1 addition & 0 deletions
1
tests/ui/async-await/async-closures/overlapping-projs.run.stdout
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 @@ | ||
1 2 |
29 changes: 29 additions & 0 deletions
29
tests/ui/async-await/async-closures/precise-captures.call.run.stdout
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,29 @@ | ||
after call | ||
after await | ||
fixed | ||
uncaptured | ||
|
||
after call | ||
after await | ||
fixed | ||
uncaptured | ||
|
||
after call | ||
after await | ||
fixed | ||
uncaptured | ||
|
||
after call | ||
after await | ||
fixed | ||
untouched | ||
|
||
after call | ||
drop first | ||
after await | ||
uncaptured | ||
|
||
after call | ||
drop first | ||
after await | ||
uncaptured |
29 changes: 29 additions & 0 deletions
29
tests/ui/async-await/async-closures/precise-captures.call_once.run.stdout
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,29 @@ | ||
after call | ||
after await | ||
fixed | ||
uncaptured | ||
|
||
after call | ||
after await | ||
fixed | ||
uncaptured | ||
|
||
after call | ||
fixed | ||
after await | ||
uncaptured | ||
|
||
after call | ||
after await | ||
fixed | ||
untouched | ||
|
||
after call | ||
drop first | ||
after await | ||
uncaptured | ||
|
||
after call | ||
drop first | ||
after await | ||
uncaptured |
Oops, something went wrong.