@@ -542,14 +542,12 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
542542 debug ! ( "univariant offset: {:?} field: {:#?}" , offset, field) ;
543543 offsets[ i as usize ] = offset;
544544
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) ;
553551 }
554552 }
555553
@@ -1078,6 +1076,29 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
10781076
10791077 let mut st = self . univariant_uninterned ( ty, & variants[ v] , & def. repr ( ) , kind) ?;
10801078 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+
10811102 let ( start, end) = self . tcx . layout_scalar_valid_range ( def. did ( ) ) ;
10821103 match st. abi {
10831104 Abi :: Scalar ( ref mut scalar) | Abi :: ScalarPair ( ref mut scalar, _) => {
@@ -1106,11 +1127,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
11061127 }
11071128
11081129 // 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) ;
11141131 if let Some ( niche) = niche {
11151132 match st. largest_niche {
11161133 Some ( largest_niche) => {
0 commit comments