]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_transmute/src/lib.rs
Auto merge of #103455 - BlackHoleFox:apple-sim-abi-consistency, r=davidtwco
[rust.git] / compiler / rustc_transmute / src / lib.rs
index 64cd70d3678777920897b2330d14b0b28d26c3fd..f7cc94e53146afaf35e3654b33ed5312f5bd4cf9 100644 (file)
@@ -80,11 +80,11 @@ pub struct Types<'tcx> {
     }
 
     pub struct TransmuteTypeEnv<'cx, 'tcx> {
-        infcx: &'cx InferCtxt<'cx, 'tcx>,
+        infcx: &'cx InferCtxt<'tcx>,
     }
 
     impl<'cx, 'tcx> TransmuteTypeEnv<'cx, 'tcx> {
-        pub fn new(infcx: &'cx InferCtxt<'cx, 'tcx>) -> Self {
+        pub fn new(infcx: &'cx InferCtxt<'tcx>) -> Self {
             Self { infcx }
         }
 
@@ -115,7 +115,7 @@ pub fn from_const<'tcx>(
             tcx: TyCtxt<'tcx>,
             param_env: ParamEnv<'tcx>,
             c: Const<'tcx>,
-        ) -> Self {
+        ) -> Option<Self> {
             use rustc_middle::ty::ScalarInt;
             use rustc_middle::ty::TypeVisitable;
             use rustc_span::symbol::sym;
@@ -123,10 +123,15 @@ pub fn from_const<'tcx>(
             let c = c.eval(tcx, param_env);
 
             if let Some(err) = c.error_reported() {
-                return Self { alignment: true, lifetimes: true, safety: true, validity: true };
+                return Some(Self {
+                    alignment: true,
+                    lifetimes: true,
+                    safety: true,
+                    validity: true,
+                });
             }
 
-            let adt_def = c.ty().ty_adt_def().expect("The given `Const` must be an ADT.");
+            let adt_def = c.ty().ty_adt_def()?;
 
             assert_eq!(
                 tcx.require_lang_item(LangItem::TransmuteOpts, None),
@@ -148,12 +153,12 @@ pub fn from_const<'tcx>(
                 fields[field_idx].unwrap_leaf() == ScalarInt::TRUE
             };
 
-            Self {
+            Some(Self {
                 alignment: get_field(sym::alignment),
                 lifetimes: get_field(sym::lifetimes),
                 safety: get_field(sym::safety),
                 validity: get_field(sym::validity),
-            }
+            })
         }
     }
 }