@@ -542,14 +542,12 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
542
542
debug ! ( "univariant offset: {:?} field: {:#?}" , offset, field) ;
543
543
offsets[ i as usize ] = offset;
544
544
545
- if !repr. hide_niche ( ) {
546
- if let Some ( mut niche) = field. largest_niche {
547
- let available = niche. available ( dl) ;
548
- if available > largest_niche_available {
549
- largest_niche_available = available;
550
- niche. offset += offset;
551
- largest_niche = Some ( niche) ;
552
- }
545
+ if let Some ( mut niche) = field. largest_niche {
546
+ let available = niche. available ( dl) ;
547
+ if available > largest_niche_available {
548
+ largest_niche_available = available;
549
+ niche. offset += offset;
550
+ largest_niche = Some ( niche) ;
553
551
}
554
552
}
555
553
@@ -1078,6 +1076,29 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1078
1076
1079
1077
let mut st = self . univariant_uninterned ( ty, & variants[ v] , & def. repr ( ) , kind) ?;
1080
1078
st. variants = Variants :: Single { index : v } ;
1079
+
1080
+ if def. is_unsafe_cell ( ) {
1081
+ let hide_niches = |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) => hide_niches ( scalar) ,
1091
+ Abi :: ScalarPair ( a, b) => {
1092
+ hide_niches ( a) ;
1093
+ hide_niches ( b) ;
1094
+ }
1095
+ Abi :: Vector { element, count : _ } => hide_niches ( element) ,
1096
+ Abi :: Aggregate { sized : _ } => { }
1097
+ }
1098
+ st. largest_niche = None ;
1099
+ return Ok ( tcx. intern_layout ( st) ) ;
1100
+ }
1101
+
1081
1102
let ( start, end) = self . tcx . layout_scalar_valid_range ( def. did ( ) ) ;
1082
1103
match st. abi {
1083
1104
Abi :: Scalar ( ref mut scalar) | Abi :: ScalarPair ( ref mut scalar, _) => {
@@ -1106,11 +1127,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1106
1127
}
1107
1128
1108
1129
// Update `largest_niche` if we have introduced a larger niche.
1109
- let niche = if def. repr ( ) . hide_niche ( ) {
1110
- None
1111
- } else {
1112
- Niche :: from_scalar ( dl, Size :: ZERO , * scalar)
1113
- } ;
1130
+ let niche = Niche :: from_scalar ( dl, Size :: ZERO , * scalar) ;
1114
1131
if let Some ( niche) = niche {
1115
1132
match st. largest_niche {
1116
1133
Some ( largest_niche) => {
0 commit comments