@@ -1076,6 +1076,34 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1076
1076
1077
1077
let mut st = self . univariant_uninterned ( ty, & variants[ v] , & def. repr ( ) , kind) ?;
1078
1078
st. variants = Variants :: Single { index : v } ;
1079
+
1080
+ if def. is_unsafe_cell ( ) {
1081
+ let fill = |scalar : & mut _ | match scalar {
1082
+ Scalar :: Initialized { value, valid_range } => {
1083
+ * valid_range = WrappingRange :: full ( value. size ( dl) )
1084
+ }
1085
+ // Already doesn't have any niches
1086
+ Scalar :: Union { .. } => { }
1087
+ } ;
1088
+ match & mut st. abi {
1089
+ Abi :: Uninhabited => { }
1090
+ Abi :: Scalar ( scalar) => fill ( scalar) ,
1091
+ Abi :: ScalarPair ( a, b) => {
1092
+ fill ( a) ;
1093
+ fill ( b) ;
1094
+ }
1095
+ Abi :: Vector { element, count : _ } => {
1096
+ // Until we support types other than floats and integers in SIMD,
1097
+ // `element` must already be a full for its range, so there's nothing to
1098
+ // do here.
1099
+ assert ! ( element. is_always_valid( dl) ) ;
1100
+ }
1101
+ Abi :: Aggregate { sized : _ } => { }
1102
+ }
1103
+ st. largest_niche = None ;
1104
+ return Ok ( tcx. intern_layout ( st) ) ;
1105
+ }
1106
+
1079
1107
let ( start, end) = self . tcx . layout_scalar_valid_range ( def. did ( ) ) ;
1080
1108
match st. abi {
1081
1109
Abi :: Scalar ( ref mut scalar) | Abi :: ScalarPair ( ref mut scalar, _) => {
@@ -1102,29 +1130,19 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1102
1130
assert ! ( valid_range. end >= end) ;
1103
1131
valid_range. end = end;
1104
1132
}
1105
- if def. is_unsafe_cell ( ) {
1106
- match scalar {
1107
- Scalar :: Initialized { value, valid_range } => {
1108
- * valid_range = WrappingRange :: full ( value. size ( dl) )
1109
- }
1110
- // Already doesn't have any niches
1111
- Scalar :: Union { .. } => { }
1112
- }
1113
- st. largest_niche = None ;
1114
- } else {
1115
- // Update `largest_niche` if we have introduced a larger niche.
1116
- let niche = Niche :: from_scalar ( dl, Size :: ZERO , * scalar) ;
1117
- if let Some ( niche) = niche {
1118
- match st. largest_niche {
1119
- Some ( largest_niche) => {
1120
- // Replace the existing niche even if they're equal,
1121
- // because this one is at a lower offset.
1122
- if largest_niche. available ( dl) <= niche. available ( dl) {
1123
- st. largest_niche = Some ( niche) ;
1124
- }
1133
+
1134
+ // Update `largest_niche` if we have introduced a larger niche.
1135
+ let niche = Niche :: from_scalar ( dl, Size :: ZERO , * scalar) ;
1136
+ if let Some ( niche) = niche {
1137
+ match st. largest_niche {
1138
+ Some ( largest_niche) => {
1139
+ // Replace the existing niche even if they're equal,
1140
+ // because this one is at a lower offset.
1141
+ if largest_niche. available ( dl) <= niche. available ( dl) {
1142
+ st. largest_niche = Some ( niche) ;
1125
1143
}
1126
- None => st. largest_niche = Some ( niche) ,
1127
1144
}
1145
+ None => st. largest_niche = Some ( niche) ,
1128
1146
}
1129
1147
}
1130
1148
}
0 commit comments