@@ -744,20 +744,28 @@ pub trait LayoutCalculator {
744744 for field in only_variant {
745745 assert ! ( field. 0 . is_sized( ) ) ;
746746
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 {
748756 // Discard valid range information and allow undef
749757 let field_abi = field. abi ( ) . to_union ( ) ;
750758
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 {
753761 // Different fields have different ABI: disable opt
754762 common_non_zst_abi_and_align = Err ( AbiMismatch ) ;
755763 } else {
756764 // Fields with the same non-Aggregate ABI should also
757765 // have the same alignment
758766 if !matches ! ( common_abi, Abi :: Aggregate { .. } ) {
759767 assert_eq ! (
760- * common_align,
768+ common_align,
761769 field. align( ) . abi,
762770 "non-Aggregate field with matching ABI but differing alignment"
763771 ) ;
@@ -768,9 +776,6 @@ pub trait LayoutCalculator {
768776 common_non_zst_abi_and_align = Ok ( Some ( ( field_abi, field. align ( ) . abi ) ) ) ;
769777 }
770778 }
771-
772- align = align. max ( field. align ( ) ) ;
773- size = cmp:: max ( size, field. size ( ) ) ;
774779 }
775780
776781 if let Some ( pack) = repr. pack {
0 commit comments