@@ -1053,6 +1053,23 @@ impl<'a, 'gcx, 'tcx> Layout {
1053
1053
let dl = & tcx. data_layout ;
1054
1054
assert ! ( !ty. has_infer_types( ) ) ;
1055
1055
1056
+ let ptr_layout = |pointee : Ty < ' gcx > | {
1057
+ let non_zero = !ty. is_unsafe_ptr ( ) ;
1058
+ let pointee = normalize_associated_type ( infcx, pointee) ;
1059
+ if pointee. is_sized ( tcx, & infcx. parameter_environment , DUMMY_SP ) {
1060
+ Ok ( Scalar { value : Pointer , non_zero : non_zero } )
1061
+ } else {
1062
+ let unsized_part = tcx. struct_tail ( pointee) ;
1063
+ let meta = match unsized_part. sty {
1064
+ ty:: TySlice ( _) | ty:: TyStr => {
1065
+ Int ( dl. ptr_sized_integer ( ) )
1066
+ }
1067
+ ty:: TyDynamic ( ..) => Pointer ,
1068
+ _ => return Err ( LayoutError :: Unknown ( unsized_part) )
1069
+ } ;
1070
+ Ok ( FatPointer { metadata : meta, non_zero : non_zero } )
1071
+ }
1072
+ } ;
1056
1073
1057
1074
let layout = match ty. sty {
1058
1075
// Basic scalars.
@@ -1082,24 +1099,12 @@ impl<'a, 'gcx, 'tcx> Layout {
1082
1099
} ,
1083
1100
1084
1101
// Potentially-fat pointers.
1085
- ty:: TyBox ( pointee) |
1086
1102
ty:: TyRef ( _, ty:: TypeAndMut { ty : pointee, .. } ) |
1087
1103
ty:: TyRawPtr ( ty:: TypeAndMut { ty : pointee, .. } ) => {
1088
- let non_zero = !ty. is_unsafe_ptr ( ) ;
1089
- let pointee = normalize_associated_type ( infcx, pointee) ;
1090
- if pointee. is_sized ( tcx, & infcx. parameter_environment , DUMMY_SP ) {
1091
- Scalar { value : Pointer , non_zero : non_zero }
1092
- } else {
1093
- let unsized_part = tcx. struct_tail ( pointee) ;
1094
- let meta = match unsized_part. sty {
1095
- ty:: TySlice ( _) | ty:: TyStr => {
1096
- Int ( dl. ptr_sized_integer ( ) )
1097
- }
1098
- ty:: TyDynamic ( ..) => Pointer ,
1099
- _ => return Err ( LayoutError :: Unknown ( unsized_part) )
1100
- } ;
1101
- FatPointer { metadata : meta, non_zero : non_zero }
1102
- }
1104
+ ptr_layout ( pointee) ?
1105
+ }
1106
+ ty:: TyAdt ( def, _) if def. is_box ( ) => {
1107
+ ptr_layout ( ty. boxed_ty ( ) ) ?
1103
1108
}
1104
1109
1105
1110
// Arrays and slices.
@@ -1560,26 +1565,32 @@ impl<'a, 'gcx, 'tcx> SizeSkeleton<'gcx> {
1560
1565
Err ( err) => err
1561
1566
} ;
1562
1567
1568
+ let ptr_skeleton = |pointee : Ty < ' gcx > | {
1569
+ let non_zero = !ty. is_unsafe_ptr ( ) ;
1570
+ let tail = tcx. struct_tail ( pointee) ;
1571
+ match tail. sty {
1572
+ ty:: TyParam ( _) | ty:: TyProjection ( _) => {
1573
+ assert ! ( tail. has_param_types( ) || tail. has_self_ty( ) ) ;
1574
+ Ok ( SizeSkeleton :: Pointer {
1575
+ non_zero : non_zero,
1576
+ tail : tcx. erase_regions ( & tail)
1577
+ } )
1578
+ }
1579
+ _ => {
1580
+ bug ! ( "SizeSkeleton::compute({}): layout errored ({}), yet \
1581
+ tail `{}` is not a type parameter or a projection",
1582
+ ty, err, tail)
1583
+ }
1584
+ }
1585
+ } ;
1586
+
1563
1587
match ty. sty {
1564
- ty:: TyBox ( pointee) |
1565
1588
ty:: TyRef ( _, ty:: TypeAndMut { ty : pointee, .. } ) |
1566
1589
ty:: TyRawPtr ( ty:: TypeAndMut { ty : pointee, .. } ) => {
1567
- let non_zero = !ty. is_unsafe_ptr ( ) ;
1568
- let tail = tcx. struct_tail ( pointee) ;
1569
- match tail. sty {
1570
- ty:: TyParam ( _) | ty:: TyProjection ( _) => {
1571
- assert ! ( tail. has_param_types( ) || tail. has_self_ty( ) ) ;
1572
- Ok ( SizeSkeleton :: Pointer {
1573
- non_zero : non_zero,
1574
- tail : tcx. erase_regions ( & tail)
1575
- } )
1576
- }
1577
- _ => {
1578
- bug ! ( "SizeSkeleton::compute({}): layout errored ({}), yet \
1579
- tail `{}` is not a type parameter or a projection",
1580
- ty, err, tail)
1581
- }
1582
- }
1590
+ ptr_skeleton ( pointee)
1591
+ }
1592
+ ty:: TyAdt ( def, _) if def. is_box ( ) => {
1593
+ ptr_skeleton ( ty. boxed_ty ( ) )
1583
1594
}
1584
1595
1585
1596
ty:: TyAdt ( def, substs) => {
0 commit comments