Skip to content

Commit

Permalink
Rollup merge of rust-lang#118935 - RalfJung:interpret-downcast, r=sae…
Browse files Browse the repository at this point in the history
…thlin

interpret: extend comment on the inhabitedness check in downcast

Cc rust-lang#115145
r? `@saethlin`
  • Loading branch information
GuillaumeGomez committed Dec 14, 2023
2 parents 2a35dfc + 5d87d83 commit a15f60d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions compiler/rustc_const_eval/src/interpret/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ where
if layout.abi.is_uninhabited() {
// `read_discriminant` should have excluded uninhabited variants... but ConstProp calls
// us on dead code.
// In the future we might want to allow this to permit code like this:
// (this is a Rust/MIR pseudocode mix)
// ```
// enum Option2 {
// Some(i32, !),
// None,
// }
//
// fn panic() -> ! { panic!() }
//
// let x: Option2;
// x.Some.0 = 42;
// x.Some.1 = panic();
// SetDiscriminant(x, Some);
// ```
// However, for now we don't generate such MIR, and this check here *has* found real
// bugs (see https://github.com/rust-lang/rust/issues/115145), so we will keep rejecting
// it.
throw_inval!(ConstPropNonsense)
}
// This cannot be `transmute` as variants *can* have a smaller size than the entire enum.
Expand Down

0 comments on commit a15f60d

Please sign in to comment.