@@ -744,20 +744,28 @@ pub trait LayoutCalculator {
744
744
for field in only_variant {
745
745
assert ! ( field. 0 . is_sized( ) ) ;
746
746
747
- if !field. 0 . is_zst ( ) && !common_non_zst_abi_and_align. is_err ( ) {
747
+ align = align. max ( field. align ( ) ) ;
748
+ size = cmp:: max ( size, field. size ( ) ) ;
749
+
750
+ if field. 0 . is_zst ( ) {
751
+ // Nothing more to do for ZST fields
752
+ continue ;
753
+ }
754
+
755
+ if let Ok ( common) = common_non_zst_abi_and_align {
748
756
// Discard valid range information and allow undef
749
757
let field_abi = field. abi ( ) . to_union ( ) ;
750
758
751
- if let Ok ( Some ( ( common_abi, common_align) ) ) = & mut common_non_zst_abi_and_align {
752
- if * common_abi != field_abi {
759
+ if let Some ( ( common_abi, common_align) ) = common {
760
+ if common_abi != field_abi {
753
761
// Different fields have different ABI: disable opt
754
762
common_non_zst_abi_and_align = Err ( AbiMismatch ) ;
755
763
} else {
756
764
// Fields with the same non-Aggregate ABI should also
757
765
// have the same alignment
758
766
if !matches ! ( common_abi, Abi :: Aggregate { .. } ) {
759
767
assert_eq ! (
760
- * common_align,
768
+ common_align,
761
769
field. align( ) . abi,
762
770
"non-Aggregate field with matching ABI but differing alignment"
763
771
) ;
@@ -768,9 +776,6 @@ pub trait LayoutCalculator {
768
776
common_non_zst_abi_and_align = Ok ( Some ( ( field_abi, field. align ( ) . abi ) ) ) ;
769
777
}
770
778
}
771
-
772
- align = align. max ( field. align ( ) ) ;
773
- size = cmp:: max ( size, field. size ( ) ) ;
774
779
}
775
780
776
781
if let Some ( pack) = repr. pack {
0 commit comments