Skip to content

Commit a15f60d

Browse files
Rollup merge of #118935 - RalfJung:interpret-downcast, r=saethlin
interpret: extend comment on the inhabitedness check in downcast Cc #115145 r? `@saethlin`
2 parents 2a35dfc + 5d87d83 commit a15f60d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

compiler/rustc_const_eval/src/interpret/projection.rs

+18
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,24 @@ where
208208
if layout.abi.is_uninhabited() {
209209
// `read_discriminant` should have excluded uninhabited variants... but ConstProp calls
210210
// us on dead code.
211+
// In the future we might want to allow this to permit code like this:
212+
// (this is a Rust/MIR pseudocode mix)
213+
// ```
214+
// enum Option2 {
215+
// Some(i32, !),
216+
// None,
217+
// }
218+
//
219+
// fn panic() -> ! { panic!() }
220+
//
221+
// let x: Option2;
222+
// x.Some.0 = 42;
223+
// x.Some.1 = panic();
224+
// SetDiscriminant(x, Some);
225+
// ```
226+
// However, for now we don't generate such MIR, and this check here *has* found real
227+
// bugs (see https://github.com/rust-lang/rust/issues/115145), so we will keep rejecting
228+
// it.
211229
throw_inval!(ConstPropNonsense)
212230
}
213231
// This cannot be `transmute` as variants *can* have a smaller size than the entire enum.

0 commit comments

Comments
 (0)