@@ -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
@@ -1104,23 +1102,29 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
11041102 assert ! ( valid_range. end >= end) ;
11051103 valid_range. end = end;
11061104 }
1107-
1108- // Update `largest_niche` if we have introduced a larger niche.
1109- let niche = if def. repr ( ) . hide_niche ( ) {
1110- None
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 ;
11111114 } else {
1112- Niche :: from_scalar ( dl, Size :: ZERO , * scalar)
1113- } ;
1114- if let Some ( niche) = niche {
1115- match st. largest_niche {
1116- Some ( largest_niche) => {
1117- // Replace the existing niche even if they're equal,
1118- // because this one is at a lower offset.
1119- if largest_niche. available ( dl) <= niche. available ( dl) {
1120- st. largest_niche = Some ( niche) ;
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+ }
11211125 }
1126+ None => st. largest_niche = Some ( niche) ,
11221127 }
1123- None => st. largest_niche = Some ( niche) ,
11241128 }
11251129 }
11261130 }
0 commit comments