Skip to content

Commit 5d87d83

Browse files
committed
interpret: extend comment on the inhabitedness check in downcast
1 parent 7176b8b commit 5d87d83

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)