@@ -2090,7 +2090,7 @@ impl LayoutOf<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
20902090
20912091impl < ' tcx , C > TyAbiInterface < ' tcx , C > for Ty < ' tcx >
20922092where
2093- C : LayoutOf < ' tcx , Ty = Ty < ' tcx > > + HasTyCtxt < ' tcx > + HasParamEnv < ' tcx > ,
2093+ C : HasTyCtxt < ' tcx > + HasParamEnv < ' tcx > ,
20942094{
20952095 fn ty_and_layout_for_variant (
20962096 this : TyAndLayout < ' tcx > ,
@@ -2109,8 +2109,11 @@ where
21092109 }
21102110
21112111 Variants :: Single { index } => {
2112+ let tcx = cx. tcx ( ) ;
2113+ let param_env = cx. param_env ( ) ;
2114+
21122115 // Deny calling for_variant more than once for non-Single enums.
2113- if let Ok ( original_layout) = cx . layout_of ( this. ty ) . to_result ( ) {
2116+ if let Ok ( original_layout) = tcx . layout_of ( param_env . and ( this. ty ) ) {
21142117 assert_eq ! ( original_layout. variants, Variants :: Single { index } ) ;
21152118 }
21162119
@@ -2120,7 +2123,6 @@ where
21202123 ty:: Adt ( def, _) => def. variants [ variant_index] . fields . len ( ) ,
21212124 _ => bug ! ( ) ,
21222125 } ;
2123- let tcx = cx. tcx ( ) ;
21242126 tcx. intern_layout ( Layout {
21252127 variants : Variants :: Single { index : variant_index } ,
21262128 fields : match NonZeroUsize :: new ( fields) {
@@ -2300,32 +2302,32 @@ where
23002302 cx : & C ,
23012303 offset : Size ,
23022304 ) -> Option < PointeeInfo > {
2305+ let tcx = cx. tcx ( ) ;
2306+ let param_env = cx. param_env ( ) ;
2307+
23032308 let addr_space_of_ty = |ty : Ty < ' tcx > | {
23042309 if ty. is_fn ( ) { cx. data_layout ( ) . instruction_address_space } else { AddressSpace :: DATA }
23052310 } ;
23062311
23072312 let pointee_info = match * this. ty . kind ( ) {
23082313 ty:: RawPtr ( mt) if offset. bytes ( ) == 0 => {
2309- cx . layout_of ( mt. ty ) . to_result ( ) . ok ( ) . map ( |layout| PointeeInfo {
2314+ tcx . layout_of ( param_env . and ( mt. ty ) ) . ok ( ) . map ( |layout| PointeeInfo {
23102315 size : layout. size ,
23112316 align : layout. align . abi ,
23122317 safe : None ,
23132318 address_space : addr_space_of_ty ( mt. ty ) ,
23142319 } )
23152320 }
23162321 ty:: FnPtr ( fn_sig) if offset. bytes ( ) == 0 => {
2317- cx. layout_of ( cx. tcx ( ) . mk_fn_ptr ( fn_sig) ) . to_result ( ) . ok ( ) . map ( |layout| {
2318- PointeeInfo {
2319- size : layout. size ,
2320- align : layout. align . abi ,
2321- safe : None ,
2322- address_space : cx. data_layout ( ) . instruction_address_space ,
2323- }
2322+ tcx. layout_of ( param_env. and ( tcx. mk_fn_ptr ( fn_sig) ) ) . ok ( ) . map ( |layout| PointeeInfo {
2323+ size : layout. size ,
2324+ align : layout. align . abi ,
2325+ safe : None ,
2326+ address_space : cx. data_layout ( ) . instruction_address_space ,
23242327 } )
23252328 }
23262329 ty:: Ref ( _, ty, mt) if offset. bytes ( ) == 0 => {
23272330 let address_space = addr_space_of_ty ( ty) ;
2328- let tcx = cx. tcx ( ) ;
23292331 let kind = if tcx. sess . opts . optimize == OptLevel :: No {
23302332 // Use conservative pointer kind if not optimizing. This saves us the
23312333 // Freeze/Unpin queries, and can save time in the codegen backend (noalias
@@ -2354,7 +2356,7 @@ where
23542356 }
23552357 } ;
23562358
2357- cx . layout_of ( ty ) . to_result ( ) . ok ( ) . map ( |layout| PointeeInfo {
2359+ tcx . layout_of ( param_env . and ( ty ) ) . ok ( ) . map ( |layout| PointeeInfo {
23582360 size : layout. size ,
23592361 align : layout. align . abi ,
23602362 safe : Some ( kind) ,
@@ -3023,16 +3025,15 @@ where
30233025 }
30243026}
30253027
3026- fn make_thin_self_ptr < ' tcx , C > ( cx : & C , mut layout : TyAndLayout < ' tcx > ) -> TyAndLayout < ' tcx >
3027- where
3028- C : LayoutOf < ' tcx , Ty = Ty < ' tcx > , TyAndLayout = TyAndLayout < ' tcx > >
3029- + HasTyCtxt < ' tcx >
3030- + HasParamEnv < ' tcx > ,
3031- {
3028+ fn make_thin_self_ptr < ' tcx > (
3029+ cx : & ( impl HasTyCtxt < ' tcx > + HasParamEnv < ' tcx > ) ,
3030+ layout : TyAndLayout < ' tcx > ,
3031+ ) -> TyAndLayout < ' tcx > {
3032+ let tcx = cx. tcx ( ) ;
30323033 let fat_pointer_ty = if layout. is_unsized ( ) {
30333034 // unsized `self` is passed as a pointer to `self`
30343035 // FIXME (mikeyhew) change this to use &own if it is ever added to the language
3035- cx . tcx ( ) . mk_mut_ptr ( layout. ty )
3036+ tcx. mk_mut_ptr ( layout. ty )
30363037 } else {
30373038 match layout. abi {
30383039 Abi :: ScalarPair ( ..) => ( ) ,
@@ -3066,8 +3067,13 @@ where
30663067 // we now have a type like `*mut RcBox<dyn Trait>`
30673068 // change its layout to that of `*mut ()`, a thin pointer, but keep the same type
30683069 // this is understood as a special case elsewhere in the compiler
3069- let unit_pointer_ty = cx. tcx ( ) . mk_mut_ptr ( cx. tcx ( ) . mk_unit ( ) ) ;
3070- layout = cx. layout_of ( unit_pointer_ty) ;
3071- layout. ty = fat_pointer_ty;
3072- layout
3070+ let unit_ptr_ty = tcx. mk_mut_ptr ( tcx. mk_unit ( ) ) ;
3071+
3072+ TyAndLayout {
3073+ ty : fat_pointer_ty,
3074+
3075+ // NOTE(eddyb) using an empty `ParamEnv`, and `unwrap`-ing the `Result`
3076+ // should always work because the type is always `*mut ()`.
3077+ ..tcx. layout_of ( ty:: ParamEnv :: reveal_all ( ) . and ( unit_ptr_ty) ) . unwrap ( )
3078+ }
30733079}
0 commit comments