@@ -1152,37 +1152,6 @@ impl<'a, 'tcx> CachedLayout {
1152
1152
} ;
1153
1153
assert ! ( !ty. has_infer_types( ) ) ;
1154
1154
1155
- let ptr_layout = |pointee : Ty < ' tcx > | {
1156
- let mut data_ptr = scalar_unit ( Pointer ) ;
1157
- if !ty. is_unsafe_ptr ( ) {
1158
- data_ptr. valid_range . start = 1 ;
1159
- }
1160
-
1161
- let pointee = tcx. normalize_associated_type_in_env ( & pointee, param_env) ;
1162
- if pointee. is_sized ( tcx, param_env, DUMMY_SP ) {
1163
- return Ok ( tcx. intern_layout ( CachedLayout :: scalar ( cx, data_ptr) ) ) ;
1164
- }
1165
-
1166
- let unsized_part = tcx. struct_tail ( pointee) ;
1167
- let metadata = match unsized_part. sty {
1168
- ty:: TyForeign ( ..) => {
1169
- return Ok ( tcx. intern_layout ( CachedLayout :: scalar ( cx, data_ptr) ) ) ;
1170
- }
1171
- ty:: TySlice ( _) | ty:: TyStr => {
1172
- scalar_unit ( Int ( dl. ptr_sized_integer ( ) , false ) )
1173
- }
1174
- ty:: TyDynamic ( ..) => {
1175
- let mut vtable = scalar_unit ( Pointer ) ;
1176
- vtable. valid_range . start = 1 ;
1177
- vtable
1178
- }
1179
- _ => return Err ( LayoutError :: Unknown ( unsized_part) )
1180
- } ;
1181
-
1182
- // Effectively a (ptr, meta) tuple.
1183
- Ok ( tcx. intern_layout ( scalar_pair ( data_ptr, metadata) ) )
1184
- } ;
1185
-
1186
1155
Ok ( match ty. sty {
1187
1156
// Basic scalars.
1188
1157
ty:: TyBool => {
@@ -1219,10 +1188,34 @@ impl<'a, 'tcx> CachedLayout {
1219
1188
// Potentially-fat pointers.
1220
1189
ty:: TyRef ( _, ty:: TypeAndMut { ty : pointee, .. } ) |
1221
1190
ty:: TyRawPtr ( ty:: TypeAndMut { ty : pointee, .. } ) => {
1222
- ptr_layout ( pointee) ?
1223
- }
1224
- ty:: TyAdt ( def, _) if def. is_box ( ) => {
1225
- ptr_layout ( ty. boxed_ty ( ) ) ?
1191
+ let mut data_ptr = scalar_unit ( Pointer ) ;
1192
+ if !ty. is_unsafe_ptr ( ) {
1193
+ data_ptr. valid_range . start = 1 ;
1194
+ }
1195
+
1196
+ let pointee = tcx. normalize_associated_type_in_env ( & pointee, param_env) ;
1197
+ if pointee. is_sized ( tcx, param_env, DUMMY_SP ) {
1198
+ return Ok ( tcx. intern_layout ( CachedLayout :: scalar ( cx, data_ptr) ) ) ;
1199
+ }
1200
+
1201
+ let unsized_part = tcx. struct_tail ( pointee) ;
1202
+ let metadata = match unsized_part. sty {
1203
+ ty:: TyForeign ( ..) => {
1204
+ return Ok ( tcx. intern_layout ( CachedLayout :: scalar ( cx, data_ptr) ) ) ;
1205
+ }
1206
+ ty:: TySlice ( _) | ty:: TyStr => {
1207
+ scalar_unit ( Int ( dl. ptr_sized_integer ( ) , false ) )
1208
+ }
1209
+ ty:: TyDynamic ( ..) => {
1210
+ let mut vtable = scalar_unit ( Pointer ) ;
1211
+ vtable. valid_range . start = 1 ;
1212
+ vtable
1213
+ }
1214
+ _ => return Err ( LayoutError :: Unknown ( unsized_part) )
1215
+ } ;
1216
+
1217
+ // Effectively a (ptr, meta) tuple.
1218
+ tcx. intern_layout ( scalar_pair ( data_ptr, metadata) )
1226
1219
}
1227
1220
1228
1221
// Arrays and slices.
@@ -1866,32 +1859,25 @@ impl<'a, 'tcx> SizeSkeleton<'tcx> {
1866
1859
Err ( err) => err
1867
1860
} ;
1868
1861
1869
- let ptr_skeleton = |pointee : Ty < ' tcx > | {
1870
- let non_zero = !ty. is_unsafe_ptr ( ) ;
1871
- let tail = tcx. struct_tail ( pointee) ;
1872
- match tail. sty {
1873
- ty:: TyParam ( _) | ty:: TyProjection ( _) => {
1874
- assert ! ( tail. has_param_types( ) || tail. has_self_ty( ) ) ;
1875
- Ok ( SizeSkeleton :: Pointer {
1876
- non_zero,
1877
- tail : tcx. erase_regions ( & tail)
1878
- } )
1879
- }
1880
- _ => {
1881
- bug ! ( "SizeSkeleton::compute({}): layout errored ({}), yet \
1882
- tail `{}` is not a type parameter or a projection",
1883
- ty, err, tail)
1884
- }
1885
- }
1886
- } ;
1887
-
1888
1862
match ty. sty {
1889
1863
ty:: TyRef ( _, ty:: TypeAndMut { ty : pointee, .. } ) |
1890
1864
ty:: TyRawPtr ( ty:: TypeAndMut { ty : pointee, .. } ) => {
1891
- ptr_skeleton ( pointee)
1892
- }
1893
- ty:: TyAdt ( def, _) if def. is_box ( ) => {
1894
- ptr_skeleton ( ty. boxed_ty ( ) )
1865
+ let non_zero = !ty. is_unsafe_ptr ( ) ;
1866
+ let tail = tcx. struct_tail ( pointee) ;
1867
+ match tail. sty {
1868
+ ty:: TyParam ( _) | ty:: TyProjection ( _) => {
1869
+ assert ! ( tail. has_param_types( ) || tail. has_self_ty( ) ) ;
1870
+ Ok ( SizeSkeleton :: Pointer {
1871
+ non_zero,
1872
+ tail : tcx. erase_regions ( & tail)
1873
+ } )
1874
+ }
1875
+ _ => {
1876
+ bug ! ( "SizeSkeleton::compute({}): layout errored ({}), yet \
1877
+ tail `{}` is not a type parameter or a projection",
1878
+ ty, err, tail)
1879
+ }
1880
+ }
1895
1881
}
1896
1882
1897
1883
ty:: TyAdt ( def, substs) => {
@@ -2153,39 +2139,6 @@ impl<'a, 'tcx> TyLayout<'tcx> {
2153
2139
C :: TyLayout : MaybeResult < TyLayout < ' tcx > >
2154
2140
{
2155
2141
let tcx = cx. tcx ( ) ;
2156
- let ptr_field_layout = |pointee : Ty < ' tcx > | {
2157
- assert ! ( i < 2 ) ;
2158
-
2159
- // Reuse the fat *T type as its own thin pointer data field.
2160
- // This provides information about e.g. DST struct pointees
2161
- // (which may have no non-DST form), and will work as long
2162
- // as the `Abi` or `FieldPlacement` is checked by users.
2163
- if i == 0 {
2164
- let nil = tcx. mk_nil ( ) ;
2165
- let ptr_ty = if self . ty . is_unsafe_ptr ( ) {
2166
- tcx. mk_mut_ptr ( nil)
2167
- } else {
2168
- tcx. mk_mut_ref ( tcx. types . re_static , nil)
2169
- } ;
2170
- return cx. layout_of ( ptr_ty) . map_same ( |mut ptr_layout| {
2171
- ptr_layout. ty = self . ty ;
2172
- ptr_layout
2173
- } ) ;
2174
- }
2175
-
2176
- let meta_ty = match tcx. struct_tail ( pointee) . sty {
2177
- ty:: TySlice ( _) |
2178
- ty:: TyStr => tcx. types . usize ,
2179
- ty:: TyDynamic ( ..) => {
2180
- // FIXME(eddyb) use an usize/fn() array with
2181
- // the correct number of vtables slots.
2182
- tcx. mk_imm_ref ( tcx. types . re_static , tcx. mk_nil ( ) )
2183
- }
2184
- _ => bug ! ( "TyLayout::field_type({:?}): not applicable" , self )
2185
- } ;
2186
- cx. layout_of ( meta_ty)
2187
- } ;
2188
-
2189
2142
cx. layout_of ( match self . ty . sty {
2190
2143
ty:: TyBool |
2191
2144
ty:: TyChar |
@@ -2203,10 +2156,35 @@ impl<'a, 'tcx> TyLayout<'tcx> {
2203
2156
// Potentially-fat pointers.
2204
2157
ty:: TyRef ( _, ty:: TypeAndMut { ty : pointee, .. } ) |
2205
2158
ty:: TyRawPtr ( ty:: TypeAndMut { ty : pointee, .. } ) => {
2206
- return ptr_field_layout ( pointee) ;
2207
- }
2208
- ty:: TyAdt ( def, _) if def. is_box ( ) => {
2209
- return ptr_field_layout ( self . ty . boxed_ty ( ) ) ;
2159
+ assert ! ( i < 2 ) ;
2160
+
2161
+ // Reuse the fat *T type as its own thin pointer data field.
2162
+ // This provides information about e.g. DST struct pointees
2163
+ // (which may have no non-DST form), and will work as long
2164
+ // as the `Abi` or `FieldPlacement` is checked by users.
2165
+ if i == 0 {
2166
+ let nil = tcx. mk_nil ( ) ;
2167
+ let ptr_ty = if self . ty . is_unsafe_ptr ( ) {
2168
+ tcx. mk_mut_ptr ( nil)
2169
+ } else {
2170
+ tcx. mk_mut_ref ( tcx. types . re_static , nil)
2171
+ } ;
2172
+ return cx. layout_of ( ptr_ty) . map_same ( |mut ptr_layout| {
2173
+ ptr_layout. ty = self . ty ;
2174
+ ptr_layout
2175
+ } ) ;
2176
+ }
2177
+
2178
+ match tcx. struct_tail ( pointee) . sty {
2179
+ ty:: TySlice ( _) |
2180
+ ty:: TyStr => tcx. types . usize ,
2181
+ ty:: TyDynamic ( ..) => {
2182
+ // FIXME(eddyb) use an usize/fn() array with
2183
+ // the correct number of vtables slots.
2184
+ tcx. mk_imm_ref ( tcx. types . re_static , tcx. mk_nil ( ) )
2185
+ }
2186
+ _ => bug ! ( "TyLayout::field_type({:?}): not applicable" , self )
2187
+ }
2210
2188
}
2211
2189
2212
2190
// Arrays and slices.
0 commit comments