Skip to content

Commit d0072a6

Browse files
committed
Auto merge of #120367 - RalfJung:project_downcast_uninhabited, r=oli-obk
interpret: project_downcast: do not ICE for uninhabited variants Fixes rust-lang/rust#120337 This assertion was already under discussion for a bit; I think the [example](rust-lang/rust#120337 (comment)) `@tmiasko` found is the final nail in the coffin. One could argue maybe MIR building should read the discriminant before projecting, but even then MIR optimizations should be allowed to remove that read, so the downcast should still not ICE. Maybe the downcast should be UB, but in this example UB already arises earlier when a value of type `E` is constructed. r? `@oli-obk`
2 parents 48d3fb7 + ee5585e commit d0072a6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Validation stops the test before the ICE we used to hit
2+
//@compile-flags: -Zmiri-disable-validation
3+
4+
#![feature(never_type)]
5+
#[derive(Copy, Clone)]
6+
pub enum E {
7+
A(!),
8+
}
9+
pub union U {
10+
u: (),
11+
e: E,
12+
}
13+
14+
fn main() {
15+
let E::A(ref _a) = unsafe { &(&U { u: () }).e };
16+
}

0 commit comments

Comments
 (0)