@@ -905,58 +905,38 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
905
905
// The size computations below assume that the padding is minimum.
906
906
// This is the case when fields are re-ordered.
907
907
let struct_reordering_opt = !def. repr . inhibit_struct_field_reordering_opt ( ) ;
908
- if struct_reordering_opt {
909
- let mut extend_niche_range = |d| {
910
- niche_variants =
911
- * niche_variants. start ( ) . min ( & d) ..=* niche_variants. end ( ) . max ( & d) ;
912
- } ;
913
908
914
- // Find the largest and second largest variant.
915
- for ( v, fields) in variants. iter_enumerated ( ) {
916
- if absent ( fields) {
917
- continue ;
918
- }
919
- let mut size = Size :: ZERO ;
920
- for & f in fields {
921
- align = align. max ( f. align ) ;
922
- size += f. size ;
923
- }
924
- if size > max_size {
925
- second_max_size = max_size;
926
- max_size = size;
927
- if let Some ( d) = dataful_variant {
928
- extend_niche_range ( d) ;
929
- }
930
- dataful_variant = Some ( v) ;
931
- } else if size == max_size {
932
- if let Some ( d) = dataful_variant {
933
- extend_niche_range ( d) ;
934
- }
935
- dataful_variant = None ;
936
- extend_niche_range ( v) ;
937
- } else {
938
- second_max_size = second_max_size. max ( size) ;
939
- extend_niche_range ( v) ;
940
- }
909
+ let mut extend_niche_range = |d| {
910
+ niche_variants =
911
+ * niche_variants. start ( ) . min ( & d) ..=* niche_variants. end ( ) . max ( & d) ;
912
+ } ;
913
+
914
+ // Find the largest and second largest variant.
915
+ for ( v, fields) in variants. iter_enumerated ( ) {
916
+ if absent ( fields) {
917
+ continue ;
941
918
}
942
- } else {
943
- // Find one non-ZST variant.
944
- ' variants: for ( v, fields) in variants. iter_enumerated ( ) {
945
- if absent ( fields) {
946
- continue ' variants;
919
+ let mut size = Size :: ZERO ;
920
+ for & f in fields {
921
+ align = align. max ( f. align ) ;
922
+ size += f. size ;
923
+ }
924
+ if size > max_size {
925
+ second_max_size = max_size;
926
+ max_size = size;
927
+ if let Some ( d) = dataful_variant {
928
+ extend_niche_range ( d) ;
947
929
}
948
- for f in fields {
949
- if !f. is_zst ( ) {
950
- if dataful_variant. is_none ( ) {
951
- dataful_variant = Some ( v) ;
952
- continue ' variants;
953
- } else {
954
- dataful_variant = None ;
955
- break ' variants;
956
- }
957
- }
958
- niche_variants = * niche_variants. start ( ) . min ( & v) ..=v
930
+ dataful_variant = Some ( v) ;
931
+ } else if size == max_size {
932
+ if let Some ( d) = dataful_variant {
933
+ extend_niche_range ( d) ;
959
934
}
935
+ dataful_variant = None ;
936
+ extend_niche_range ( v) ;
937
+ } else {
938
+ second_max_size = second_max_size. max ( size) ;
939
+ extend_niche_range ( v) ;
960
940
}
961
941
}
962
942
@@ -992,14 +972,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
992
972
{
993
973
return None ;
994
974
}
975
+ } else if second_max_size > Size :: ZERO {
976
+ return None ;
995
977
}
996
978
Some ( ( field_index, niche, niche. reserve ( self , count) ?) )
997
979
} ) ;
998
980
999
981
if let Some ( ( field_index, niche, ( niche_start, niche_scalar) ) ) =
1000
982
niche_candidate
1001
983
{
1002
- let mut align = dl. aggregate_align ;
1003
984
let prefix = niche. offset + niche. scalar . value . size ( dl) ;
1004
985
let st = variants
1005
986
. iter_enumerated ( )
@@ -1019,8 +1000,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1019
1000
) ?;
1020
1001
st. variants = Variants :: Single { index : j } ;
1021
1002
1022
- align = align. max ( st. align ) ;
1023
-
1003
+ debug_assert_eq ! ( align, align. max( st. align) ) ;
1024
1004
Ok ( st)
1025
1005
} )
1026
1006
. collect :: < Result < IndexVec < VariantIdx , _ > , _ > > ( ) ?;
0 commit comments