1- use  rustc_middle:: ty:: layout:: { LayoutCx ,  LayoutOf ,  TyAndLayout } ; 
2- use  rustc_middle:: ty:: { ParamEnv ,  TyCtxt } ; 
1+ use  rustc_middle:: ty:: layout:: { LayoutCx ,  LayoutError ,   LayoutOf ,  TyAndLayout } ; 
2+ use  rustc_middle:: ty:: { ParamEnv ,  ParamEnvAnd ,   Ty ,   TyCtxt } ; 
33use  rustc_session:: Limit ; 
44use  rustc_target:: abi:: { Abi ,  FieldsShape ,  InitKind ,  Scalar ,  Variants } ; 
55
@@ -20,15 +20,14 @@ use crate::interpret::{InterpCx, MemoryKind, OpTy};
2020/// to the full uninit check). 
2121pub  fn  might_permit_raw_init < ' tcx > ( 
2222    tcx :  TyCtxt < ' tcx > , 
23-     param_env :  ParamEnv < ' tcx > , 
24-     ty :  TyAndLayout < ' tcx > , 
23+     param_env_and_ty :  ParamEnvAnd < ' tcx ,  Ty < ' tcx > > , 
2524    kind :  InitKind , 
26- )  -> bool  { 
25+ )  -> Result < bool ,   LayoutError < ' tcx > >  { 
2726    if  tcx. sess . opts . unstable_opts . strict_init_checks  { 
28-         might_permit_raw_init_strict ( ty ,  tcx,  kind) 
27+         might_permit_raw_init_strict ( tcx . layout_of ( param_env_and_ty ) ? ,  tcx,  kind) 
2928    }  else  { 
30-         let  layout_cx = LayoutCx  {  tcx,  param_env } ; 
31-         might_permit_raw_init_lax ( ty ,  & layout_cx,  kind) 
29+         let  layout_cx = LayoutCx  {  tcx,  param_env :  param_env_and_ty . param_env  } ; 
30+         might_permit_raw_init_lax ( tcx . layout_of ( param_env_and_ty ) ? ,  & layout_cx,  kind) 
3231    } 
3332} 
3433
@@ -38,7 +37,7 @@ fn might_permit_raw_init_strict<'tcx>(
3837    ty :  TyAndLayout < ' tcx > , 
3938    tcx :  TyCtxt < ' tcx > , 
4039    kind :  InitKind , 
41- )  -> bool  { 
40+ )  -> Result < bool ,   LayoutError < ' tcx > >  { 
4241    let  machine = CompileTimeInterpreter :: new ( 
4342        Limit :: new ( 0 ) , 
4443        /*can_access_statics:*/  false , 
@@ -65,7 +64,7 @@ fn might_permit_raw_init_strict<'tcx>(
6564    // This does *not* actually check that references are dereferenceable, but since all types that 
6665    // require dereferenceability also require non-null, we don't actually get any false negatives 
6766    // due to this. 
68-     cx. validate_operand ( & ot) . is_ok ( ) 
67+     Ok ( cx. validate_operand ( & ot) . is_ok ( ) ) 
6968} 
7069
7170/// Implements the 'lax' (default) version of the `might_permit_raw_init` checks; see that function for 
@@ -74,7 +73,7 @@ fn might_permit_raw_init_lax<'tcx>(
7473    this :  TyAndLayout < ' tcx > , 
7574    cx :  & LayoutCx < ' tcx ,  TyCtxt < ' tcx > > , 
7675    init_kind :  InitKind , 
77- )  -> bool  { 
76+ )  -> Result < bool ,   LayoutError < ' tcx > >  { 
7877    let  scalar_allows_raw_init = move  |s :  Scalar | -> bool  { 
7978        match  init_kind { 
8079            InitKind :: Zero  => { 
@@ -103,20 +102,20 @@ fn might_permit_raw_init_lax<'tcx>(
103102    } ; 
104103    if  !valid { 
105104        // This is definitely not okay. 
106-         return  false ; 
105+         return  Ok ( false ) ; 
107106    } 
108107
109108    // Special magic check for references and boxes (i.e., special pointer types). 
110109    if  let  Some ( pointee)  = this. ty . builtin_deref ( false )  { 
111-         let  pointee = cx. layout_of ( pointee. ty ) . expect ( "need to be able to compute layouts" ) ; 
110+         let  pointee = cx. layout_of ( pointee. ty ) ? ; 
112111        // We need to ensure that the LLVM attributes `aligned` and `dereferenceable(size)` are satisfied. 
113112        if  pointee. align . abi . bytes ( )  > 1  { 
114113            // 0x01-filling is not aligned. 
115-             return  false ; 
114+             return  Ok ( false ) ; 
116115        } 
117116        if  pointee. size . bytes ( )  > 0  { 
118117            // A 'fake' integer pointer is not sufficiently dereferenceable. 
119-             return  false ; 
118+             return  Ok ( false ) ; 
120119        } 
121120    } 
122121
@@ -129,9 +128,9 @@ fn might_permit_raw_init_lax<'tcx>(
129128        } 
130129        FieldsShape :: Arbitrary  {  offsets,  .. }  => { 
131130            for  idx in  0 ..offsets. len ( )  { 
132-                 if  !might_permit_raw_init_lax ( this. field ( cx,  idx) ,  cx,  init_kind)  { 
131+                 if  !might_permit_raw_init_lax ( this. field ( cx,  idx) ,  cx,  init_kind) ?  { 
133132                    // We found a field that is unhappy with this kind of initialization. 
134-                     return  false ; 
133+                     return  Ok ( false ) ; 
135134                } 
136135            } 
137136        } 
@@ -148,5 +147,5 @@ fn might_permit_raw_init_lax<'tcx>(
148147        } 
149148    } 
150149
151-     true 
150+     Ok ( true ) 
152151} 
0 commit comments