@@ -356,12 +356,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
356356 debug ! ( "univariant offset: {:?} field: {:#?}" , offset, field) ;
357357 offsets[ i as usize ] = offset;
358358
359- if let Some ( mut niche) = field. largest_niche . clone ( ) {
360- let available = niche. available ( dl) ;
361- if available > largest_niche_available {
362- largest_niche_available = available;
363- niche. offset += offset;
364- largest_niche = Some ( niche) ;
359+ if !repr. hide_niche ( ) {
360+ if let Some ( mut niche) = field. largest_niche . clone ( ) {
361+ let available = niche. available ( dl) ;
362+ if available > largest_niche_available {
363+ largest_niche_available = available;
364+ niche. offset += offset;
365+ largest_niche = Some ( niche) ;
366+ }
365367 }
366368 }
367369
@@ -838,7 +840,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
838840 }
839841
840842 // Update `largest_niche` if we have introduced a larger niche.
841- let niche = Niche :: from_scalar ( dl, Size :: ZERO , scalar. clone ( ) ) ;
843+ let niche = if def. repr . hide_niche ( ) {
844+ None
845+ } else {
846+ Niche :: from_scalar ( dl, Size :: ZERO , scalar. clone ( ) )
847+ } ;
842848 if let Some ( niche) = niche {
843849 match & st. largest_niche {
844850 Some ( largest_niche) => {
@@ -863,6 +869,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
863869 return Ok ( tcx. intern_layout ( st) ) ;
864870 }
865871
872+ // At this point, we have handled all unions and
873+ // structs. (We have also handled univariant enums
874+ // that allow representation optimization.)
875+ assert ! ( def. is_enum( ) ) ;
876+
866877 // The current code for niche-filling relies on variant indices
867878 // instead of actual discriminants, so dataful enums with
868879 // explicit discriminants (RFC #2363) would misbehave.
0 commit comments