@@ -876,6 +876,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
876
876
. iter_enumerated ( )
877
877
. all ( |( i, v) | v. discr == ty:: VariantDiscr :: Relative ( i. as_u32 ( ) ) ) ;
878
878
879
+ let mut niche_filling_layout = None ;
880
+
879
881
// Niche-filling enum optimization.
880
882
if !def. repr . inhibit_enum_layout_opt ( ) && no_explicit_discriminants {
881
883
let mut dataful_variant = None ;
@@ -972,7 +974,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
972
974
let largest_niche =
973
975
Niche :: from_scalar ( dl, offset, niche_scalar. clone ( ) ) ;
974
976
975
- return Ok ( tcx . intern_layout ( Layout {
977
+ niche_filling_layout = Some ( Layout {
976
978
variants : Variants :: Multiple {
977
979
tag : niche_scalar,
978
980
tag_encoding : TagEncoding :: Niche {
@@ -991,7 +993,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
991
993
largest_niche,
992
994
size,
993
995
align,
994
- } ) ) ;
996
+ } ) ;
995
997
}
996
998
}
997
999
}
@@ -1214,7 +1216,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1214
1216
1215
1217
let largest_niche = Niche :: from_scalar ( dl, Size :: ZERO , tag. clone ( ) ) ;
1216
1218
1217
- tcx . intern_layout ( Layout {
1219
+ let tagged_layout = Layout {
1218
1220
variants : Variants :: Multiple {
1219
1221
tag,
1220
1222
tag_encoding : TagEncoding :: Direct ,
@@ -1229,7 +1231,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1229
1231
abi,
1230
1232
align,
1231
1233
size,
1232
- } )
1234
+ } ;
1235
+
1236
+ tcx. intern_layout ( niche_filling_layout. unwrap_or ( tagged_layout) )
1233
1237
}
1234
1238
1235
1239
// Types with no meaningful known layout.
0 commit comments