about summary refs log tree commit diff
path: root/compiler/rustc_transmute/src/lib.rs
diff options
context:
space:
mode:
authorLukas Markeffsky <@>2025-02-08 05:13:28 +0100
committerLukas Markeffsky <@>2025-02-08 05:44:29 +0100
commitc097b2c6bb63e793d30191ffdcaf30c8e0d48607 (patch)
treea659edc95cffe5ab6a59ae7924f326c4bbf0bd23 /compiler/rustc_transmute/src/lib.rs
parente0607238c95df66e3d25a6c17aebe18c6726fc74 (diff)
downloadrust-c097b2c6bb63e793d30191ffdcaf30c8e0d48607.tar.gz
rust-c097b2c6bb63e793d30191ffdcaf30c8e0d48607.zip
transmutability: fix ICE when passing wrong ADT to ASSUME
Diffstat (limited to 'compiler/rustc_transmute/src/lib.rs')
-rw-r--r--compiler/rustc_transmute/src/lib.rs32
1 files changed, 14 insertions, 18 deletions
diff --git a/compiler/rustc_transmute/src/lib.rs b/compiler/rustc_transmute/src/lib.rs
index a50cc8f5932..f9537f708ef 100644
--- a/compiler/rustc_transmute/src/lib.rs
+++ b/compiler/rustc_transmute/src/lib.rs
@@ -84,7 +84,7 @@ mod rustc {
     use rustc_infer::infer::InferCtxt;
     use rustc_macros::TypeVisitable;
     use rustc_middle::traits::ObligationCause;
-    use rustc_middle::ty::{Const, ParamEnv, Ty, TyCtxt, ValTree};
+    use rustc_middle::ty::{Const, ParamEnv, Ty, TyCtxt};
 
     use super::*;
 
@@ -139,25 +139,21 @@ mod rustc {
 
             let adt_def = cv.ty.ty_adt_def()?;
 
-            assert_eq!(
-                tcx.require_lang_item(LangItem::TransmuteOpts, None),
-                adt_def.did(),
-                "The given `Const` was not marked with the `{}` lang item.",
-                LangItem::TransmuteOpts.name(),
-            );
+            if !tcx.is_lang_item(adt_def.did(), LangItem::TransmuteOpts) {
+                tcx.dcx().delayed_bug(format!(
+                    "The given `const` was not marked with the `{}` lang item.",
+                    LangItem::TransmuteOpts.name()
+                ));
+                return Some(Self {
+                    alignment: true,
+                    lifetimes: true,
+                    safety: true,
+                    validity: true,
+                });
+            }
 
             let variant = adt_def.non_enum_variant();
-            let fields = match cv.valtree {
-                ValTree::Branch(branch) => branch,
-                _ => {
-                    return Some(Self {
-                        alignment: true,
-                        lifetimes: true,
-                        safety: true,
-                        validity: true,
-                    });
-                }
-            };
+            let fields = cv.valtree.unwrap_branch();
 
             let get_field = |name| {
                 let (field_idx, _) = variant