about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-12-14 20:33:11 +0100
committerGitHub <noreply@github.com>2023-12-14 20:33:11 +0100
commit49a2fc22e9186b414a8da18af94fe6ebb0a00462 (patch)
tree0addbdb35765101e780492e68c11b966f0a00998 /compiler/rustc_const_eval/src/interpret
parentaccaea27955ca30fc8c5e2bacd10b3094e89eee8 (diff)
parent5d87d8307f460a16167416a0e808bcb1c74295b4 (diff)
downloadrust-49a2fc22e9186b414a8da18af94fe6ebb0a00462.tar.gz
rust-49a2fc22e9186b414a8da18af94fe6ebb0a00462.zip
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``
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
-rw-r--r--compiler/rustc_const_eval/src/interpret/projection.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/projection.rs b/compiler/rustc_const_eval/src/interpret/projection.rs
index 0f3b6b25c61..9a034ba22b9 100644
--- a/compiler/rustc_const_eval/src/interpret/projection.rs
+++ b/compiler/rustc_const_eval/src/interpret/projection.rs
@@ -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.