Rollup merge of #118935 - RalfJung:interpret-downcast, r=saethlin
interpret: extend comment on the inhabitedness check in downcast Cc https://github.com/rust-lang/rust/issues/115145 r? ``@saethlin``
This commit is contained in:
commit
49a2fc22e9
1 changed files with 18 additions and 0 deletions
|
@ -208,6 +208,24 @@ where
|
||||||
if layout.abi.is_uninhabited() {
|
if layout.abi.is_uninhabited() {
|
||||||
// `read_discriminant` should have excluded uninhabited variants... but ConstProp calls
|
// `read_discriminant` should have excluded uninhabited variants... but ConstProp calls
|
||||||
// us on dead code.
|
// 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)
|
throw_inval!(ConstPropNonsense)
|
||||||
}
|
}
|
||||||
// This cannot be `transmute` as variants *can* have a smaller size than the entire enum.
|
// This cannot be `transmute` as variants *can* have a smaller size than the entire enum.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue