-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #127136 - compiler-errors:coroutine-closure-env-shim,…
… r=oli-obk Fix `FnMut::call_mut`/`Fn::call` shim for async closures that capture references I adjusted async closures to be able to implement `Fn` and `FnMut` *even if* they capture references, as long as those references did not need to borrow data from the closure captures themselves. See #125259. However, when I did this, I didn't actually relax an assertion in the `build_construct_coroutine_by_move_shim` shim code, which builds the `Fn`/`FnMut`/`FnOnce` implementations for async closures. Therefore, if we actually tried to *call* `FnMut`/`Fn` on async closures, it would ICE. This PR adjusts this assertion to ensure that we only capture immutable references in closures if they implement `Fn`/`FnMut`. It also adds a bunch of tests and makes more of the async-closure tests into `build-pass` since we often care about these tests actually generating the right closure shims and stuff. I think it might be excessive to *always* use build-pass here, but 🤷 it's not that big of a deal. Fixes #127019 Fixes #127012 r? oli-obk
- Loading branch information
Showing
23 changed files
with
225 additions
and
58 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
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
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
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
0 2 | ||
0 2 | ||
1 2 | ||
1 2 | ||
1 2 | ||
1 2 | ||
0 | ||
1 |
2 changes: 1 addition & 1 deletion
2
...losure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.panic-abort.mir
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
2 changes: 1 addition & 1 deletion
2
...osure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.panic-unwind.mir
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
6 changes: 3 additions & 3 deletions
6
...nc_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-abort.mir
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
// MIR for `main::{closure#0}::{closure#0}` 0 coroutine_closure_by_move | ||
|
||
fn main::{closure#0}::{closure#0}(_1: {async closure@$DIR/async_closure_shims.rs:42:33: 42:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:42:53: 45:10} { | ||
let mut _0: {async closure body@$DIR/async_closure_shims.rs:42:53: 45:10}; | ||
fn main::{closure#0}::{closure#0}(_1: {async closure@$DIR/async_closure_shims.rs:53:33: 53:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:53:53: 56:10} { | ||
let mut _0: {async closure body@$DIR/async_closure_shims.rs:53:53: 56:10}; | ||
|
||
bb0: { | ||
_0 = {coroutine@$DIR/async_closure_shims.rs:42:53: 45:10 (#0)} { a: move _2, b: move (_1.0: i32) }; | ||
_0 = {coroutine@$DIR/async_closure_shims.rs:53:53: 56:10 (#0)} { a: move _2, b: move (_1.0: i32) }; | ||
return; | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...c_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-unwind.mir
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
// MIR for `main::{closure#0}::{closure#0}` 0 coroutine_closure_by_move | ||
|
||
fn main::{closure#0}::{closure#0}(_1: {async closure@$DIR/async_closure_shims.rs:42:33: 42:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:42:53: 45:10} { | ||
let mut _0: {async closure body@$DIR/async_closure_shims.rs:42:53: 45:10}; | ||
fn main::{closure#0}::{closure#0}(_1: {async closure@$DIR/async_closure_shims.rs:53:33: 53:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:53:53: 56:10} { | ||
let mut _0: {async closure body@$DIR/async_closure_shims.rs:53:53: 56:10}; | ||
|
||
bb0: { | ||
_0 = {coroutine@$DIR/async_closure_shims.rs:42:53: 45:10 (#0)} { a: move _2, b: move (_1.0: i32) }; | ||
_0 = {coroutine@$DIR/async_closure_shims.rs:53:53: 56:10 (#0)} { a: move _2, b: move (_1.0: i32) }; | ||
return; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...losure_shims.main-{closure#0}-{closure#1}-{closure#0}.coroutine_by_move.0.panic-abort.mir
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,47 @@ | ||
// MIR for `main::{closure#0}::{closure#1}::{closure#0}` 0 coroutine_by_move | ||
|
||
fn main::{closure#0}::{closure#1}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10}, _2: ResumeTy) -> () | ||
yields () | ||
{ | ||
debug _task_context => _2; | ||
debug a => (_1.0: i32); | ||
debug b => (*(_1.1: &i32)); | ||
let mut _0: (); | ||
let _3: i32; | ||
scope 1 { | ||
debug a => _3; | ||
let _4: &i32; | ||
scope 2 { | ||
debug a => _4; | ||
let _5: &i32; | ||
scope 3 { | ||
debug b => _5; | ||
} | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_3); | ||
_3 = (_1.0: i32); | ||
FakeRead(ForLet(None), _3); | ||
StorageLive(_4); | ||
_4 = &_3; | ||
FakeRead(ForLet(None), _4); | ||
StorageLive(_5); | ||
_5 = &(*(_1.1: &i32)); | ||
FakeRead(ForLet(None), _5); | ||
_0 = const (); | ||
StorageDead(_5); | ||
StorageDead(_4); | ||
StorageDead(_3); | ||
drop(_1) -> [return: bb1, unwind: bb2]; | ||
} | ||
|
||
bb1: { | ||
return; | ||
} | ||
|
||
bb2 (cleanup): { | ||
resume; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...osure_shims.main-{closure#0}-{closure#1}-{closure#0}.coroutine_by_move.0.panic-unwind.mir
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,47 @@ | ||
// MIR for `main::{closure#0}::{closure#1}::{closure#0}` 0 coroutine_by_move | ||
|
||
fn main::{closure#0}::{closure#1}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10}, _2: ResumeTy) -> () | ||
yields () | ||
{ | ||
debug _task_context => _2; | ||
debug a => (_1.0: i32); | ||
debug b => (*(_1.1: &i32)); | ||
let mut _0: (); | ||
let _3: i32; | ||
scope 1 { | ||
debug a => _3; | ||
let _4: &i32; | ||
scope 2 { | ||
debug a => _4; | ||
let _5: &i32; | ||
scope 3 { | ||
debug b => _5; | ||
} | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_3); | ||
_3 = (_1.0: i32); | ||
FakeRead(ForLet(None), _3); | ||
StorageLive(_4); | ||
_4 = &_3; | ||
FakeRead(ForLet(None), _4); | ||
StorageLive(_5); | ||
_5 = &(*(_1.1: &i32)); | ||
FakeRead(ForLet(None), _5); | ||
_0 = const (); | ||
StorageDead(_5); | ||
StorageDead(_4); | ||
StorageDead(_3); | ||
drop(_1) -> [return: bb1, unwind: bb2]; | ||
} | ||
|
||
bb1: { | ||
return; | ||
} | ||
|
||
bb2 (cleanup): { | ||
resume; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...nc_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_move.0.panic-abort.mir
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,10 @@ | ||
// MIR for `main::{closure#0}::{closure#1}` 0 coroutine_closure_by_move | ||
|
||
fn main::{closure#0}::{closure#1}(_1: {async closure@$DIR/async_closure_shims.rs:62:33: 62:47}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10} { | ||
let mut _0: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10}; | ||
|
||
bb0: { | ||
_0 = {coroutine@$DIR/async_closure_shims.rs:62:48: 65:10 (#0)} { a: move _2, b: move (_1.0: &i32) }; | ||
return; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...c_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_move.0.panic-unwind.mir
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,10 @@ | ||
// MIR for `main::{closure#0}::{closure#1}` 0 coroutine_closure_by_move | ||
|
||
fn main::{closure#0}::{closure#1}(_1: {async closure@$DIR/async_closure_shims.rs:62:33: 62:47}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10} { | ||
let mut _0: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10}; | ||
|
||
bb0: { | ||
_0 = {coroutine@$DIR/async_closure_shims.rs:62:48: 65:10 (#0)} { a: move _2, b: move (_1.0: &i32) }; | ||
return; | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...ync_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.panic-abort.mir
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
// MIR for `main::{closure#0}::{closure#1}` 0 coroutine_closure_by_ref | ||
|
||
fn main::{closure#0}::{closure#1}(_1: &mut {async closure@$DIR/async_closure_shims.rs:49:29: 49:48}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:49:49: 51:10} { | ||
let mut _0: {async closure body@$DIR/async_closure_shims.rs:49:49: 51:10}; | ||
fn main::{closure#0}::{closure#1}(_1: &{async closure@$DIR/async_closure_shims.rs:62:33: 62:47}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10} { | ||
let mut _0: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10}; | ||
|
||
bb0: { | ||
_0 = {coroutine@$DIR/async_closure_shims.rs:49:49: 51:10 (#0)} { a: move _2 }; | ||
_0 = {coroutine@$DIR/async_closure_shims.rs:62:48: 65:10 (#0)} { a: move _2, b: ((*_1).0: &i32) }; | ||
return; | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...nc_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.panic-unwind.mir
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
// MIR for `main::{closure#0}::{closure#1}` 0 coroutine_closure_by_ref | ||
|
||
fn main::{closure#0}::{closure#1}(_1: &mut {async closure@$DIR/async_closure_shims.rs:49:29: 49:48}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:49:49: 51:10} { | ||
let mut _0: {async closure body@$DIR/async_closure_shims.rs:49:49: 51:10}; | ||
fn main::{closure#0}::{closure#1}(_1: &{async closure@$DIR/async_closure_shims.rs:62:33: 62:47}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10} { | ||
let mut _0: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10}; | ||
|
||
bb0: { | ||
_0 = {coroutine@$DIR/async_closure_shims.rs:49:49: 51:10 (#0)} { a: move _2 }; | ||
_0 = {coroutine@$DIR/async_closure_shims.rs:62:48: 65:10 (#0)} { a: move _2, b: ((*_1).0: &i32) }; | ||
return; | ||
} | ||
} |
Oops, something went wrong.