@@ -356,12 +356,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
356
356
debug ! ( "univariant offset: {:?} field: {:#?}" , offset, field) ;
357
357
offsets[ i as usize ] = offset;
358
358
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
+ }
365
367
}
366
368
}
367
369
@@ -838,7 +840,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
838
840
}
839
841
840
842
// 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
+ } ;
842
848
if let Some ( niche) = niche {
843
849
match & st. largest_niche {
844
850
Some ( largest_niche) => {
@@ -863,6 +869,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
863
869
return Ok ( tcx. intern_layout ( st) ) ;
864
870
}
865
871
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
+
866
877
// The current code for niche-filling relies on variant indices
867
878
// instead of actual discriminants, so dataful enums with
868
879
// explicit discriminants (RFC #2363) would misbehave.
0 commit comments