Skip to content

Commit ff5187f

Browse files
Proactively update coroutine drop shim's phase to account for later passes applied during shim query
1 parent e62d47d commit ff5187f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,13 @@ fn create_coroutine_drop_shim<'tcx>(
11691169
dump_mir(tcx, false, "coroutine_drop", &0, &body, |_, _| Ok(()));
11701170
body.source.instance = drop_instance;
11711171

1172+
// Creating a coroutine drop shim happens on `Analysis(PostCleanup) -> Runtime(Initial)`
1173+
// but the pass manager doesn't update the phase of the coroutine drop shim. Update the
1174+
// phase of the drop shim so that later on when we run the pass manager on the shim, in
1175+
// the `mir_shims` query, we don't ICE on the intra-pass validation before we've updated
1176+
// the phase of the body from analysis.
1177+
body.phase = MirPhase::Runtime(RuntimePhase::Initial);
1178+
11721179
body
11731180
}
11741181

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ compile-flags: --edition=2024 -Zvalidate-mir
2+
//@ build-pass
3+
4+
// Regression test that we don't ICE when encountering a transmute in a coroutine's
5+
// drop shim body, which is conceptually in the Runtime phase but wasn't having the
6+
// phase updated b/c the pass manager neither optimizes nor updates the phase for
7+
// drop shim bodies.
8+
9+
struct HasDrop;
10+
impl Drop for HasDrop {
11+
fn drop(&mut self) {}
12+
}
13+
14+
fn main() {
15+
async {
16+
vec![async { HasDrop }.await];
17+
};
18+
}

0 commit comments

Comments
 (0)