Skip to content

Commit

Permalink
Auto merge of #120367 - RalfJung:project_downcast_uninhabited, r=oli-obk
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed Jan 26, 2024
2 parents 48d3fb7 + ee5585e commit d0072a6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/pass/issues/issue-120337-irrefutable-let-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Validation stops the test before the ICE we used to hit
//@compile-flags: -Zmiri-disable-validation

#![feature(never_type)]
#[derive(Copy, Clone)]
pub enum E {
A(!),
}
pub union U {
u: (),
e: E,
}

fn main() {
let E::A(ref _a) = unsafe { &(&U { u: () }).e };
}

0 comments on commit d0072a6

Please sign in to comment.