@@ -2090,7 +2090,7 @@ impl LayoutOf<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
2090
2090
2091
2091
impl < ' tcx , C > TyAbiInterface < ' tcx , C > for Ty < ' tcx >
2092
2092
where
2093
- C : LayoutOf < ' tcx , Ty = Ty < ' tcx > > + HasTyCtxt < ' tcx > + HasParamEnv < ' tcx > ,
2093
+ C : HasTyCtxt < ' tcx > + HasParamEnv < ' tcx > ,
2094
2094
{
2095
2095
fn ty_and_layout_for_variant (
2096
2096
this : TyAndLayout < ' tcx > ,
@@ -2109,8 +2109,11 @@ where
2109
2109
}
2110
2110
2111
2111
Variants :: Single { index } => {
2112
+ let tcx = cx. tcx ( ) ;
2113
+ let param_env = cx. param_env ( ) ;
2114
+
2112
2115
// 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 ) ) {
2114
2117
assert_eq ! ( original_layout. variants, Variants :: Single { index } ) ;
2115
2118
}
2116
2119
@@ -2120,7 +2123,6 @@ where
2120
2123
ty:: Adt ( def, _) => def. variants [ variant_index] . fields . len ( ) ,
2121
2124
_ => bug ! ( ) ,
2122
2125
} ;
2123
- let tcx = cx. tcx ( ) ;
2124
2126
tcx. intern_layout ( Layout {
2125
2127
variants : Variants :: Single { index : variant_index } ,
2126
2128
fields : match NonZeroUsize :: new ( fields) {
@@ -2300,32 +2302,32 @@ where
2300
2302
cx : & C ,
2301
2303
offset : Size ,
2302
2304
) -> Option < PointeeInfo > {
2305
+ let tcx = cx. tcx ( ) ;
2306
+ let param_env = cx. param_env ( ) ;
2307
+
2303
2308
let addr_space_of_ty = |ty : Ty < ' tcx > | {
2304
2309
if ty. is_fn ( ) { cx. data_layout ( ) . instruction_address_space } else { AddressSpace :: DATA }
2305
2310
} ;
2306
2311
2307
2312
let pointee_info = match * this. ty . kind ( ) {
2308
2313
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 {
2310
2315
size : layout. size ,
2311
2316
align : layout. align . abi ,
2312
2317
safe : None ,
2313
2318
address_space : addr_space_of_ty ( mt. ty ) ,
2314
2319
} )
2315
2320
}
2316
2321
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 ,
2324
2327
} )
2325
2328
}
2326
2329
ty:: Ref ( _, ty, mt) if offset. bytes ( ) == 0 => {
2327
2330
let address_space = addr_space_of_ty ( ty) ;
2328
- let tcx = cx. tcx ( ) ;
2329
2331
let kind = if tcx. sess . opts . optimize == OptLevel :: No {
2330
2332
// Use conservative pointer kind if not optimizing. This saves us the
2331
2333
// Freeze/Unpin queries, and can save time in the codegen backend (noalias
@@ -2354,7 +2356,7 @@ where
2354
2356
}
2355
2357
} ;
2356
2358
2357
- cx . layout_of ( ty ) . to_result ( ) . ok ( ) . map ( |layout| PointeeInfo {
2359
+ tcx . layout_of ( param_env . and ( ty ) ) . ok ( ) . map ( |layout| PointeeInfo {
2358
2360
size : layout. size ,
2359
2361
align : layout. align . abi ,
2360
2362
safe : Some ( kind) ,
@@ -3023,16 +3025,15 @@ where
3023
3025
}
3024
3026
}
3025
3027
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 ( ) ;
3032
3033
let fat_pointer_ty = if layout. is_unsized ( ) {
3033
3034
// unsized `self` is passed as a pointer to `self`
3034
3035
// 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 )
3036
3037
} else {
3037
3038
match layout. abi {
3038
3039
Abi :: ScalarPair ( ..) => ( ) ,
@@ -3066,8 +3067,13 @@ where
3066
3067
// we now have a type like `*mut RcBox<dyn Trait>`
3067
3068
// change its layout to that of `*mut ()`, a thin pointer, but keep the same type
3068
3069
// 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
+ }
3073
3079
}
0 commit comments