@@ -430,8 +430,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
430430 ( Some ( ( i, field) ) , None , None ) => {
431431 // Field fills the struct and it has a scalar or scalar pair ABI.
432432 if offsets[ i] . bytes ( ) == 0 &&
433- pref_pos. size == field. pref_pos . size &&
434- pref_pos. align . abi == field. pref_pos . align . abi {
433+ pref_pos. mem_pos ( ) == field. pref_pos . mem_pos ( ) {
435434 match field. abi {
436435 // For plain scalars, or vectors of them, we can't unpack
437436 // newtypes for `#[repr(C)]`, as that affects C ABIs.
@@ -625,7 +624,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
625624 tcx. intern_layout ( LayoutDetails {
626625 variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
627626 fields : FieldPlacement :: Array {
628- stride : element. pref_pos . size ,
627+ stride : element. pref_pos . stride ( ) ,
629628 count
630629 } ,
631630 abi,
@@ -741,23 +740,23 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
741740 bug ! ( "union cannot be packed and aligned" ) ;
742741 }
743742
744- let mut align = if def. repr . pack . is_some ( ) {
743+ let base_align = if def. repr . pack . is_some ( ) {
745744 dl. i8_align
746745 } else {
747746 dl. aggregate_align
748747 } ;
749748
749+ let mut pref_pos = LayoutPositionPref :: new ( Size :: ZERO , base_align) ;
750+
750751 if let Some ( repr_align) = def. repr . align {
751- align = align . max ( AbiAndPrefAlign :: new ( repr_align) ) ;
752+ pref_pos = pref_pos . align_to ( AbiAndPrefAlign :: new ( repr_align) ) ;
752753 }
753754
754755 let optimize = !def. repr . inhibit_union_abi_opt ( ) ;
755- let mut size = Size :: ZERO ;
756756 let mut abi = Abi :: Aggregate { sized : true } ;
757757 let index = VariantIdx :: new ( 0 ) ;
758758 for field in & variants[ index] {
759759 assert ! ( !field. is_unsized( ) ) ;
760- align = align. max ( field. pref_pos . align ) ;
761760
762761 // If all non-ZST fields have the same ABI, forward this ABI
763762 if optimize && !field. is_zst ( ) {
@@ -780,23 +779,23 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
780779 Abi :: Aggregate { .. } => Abi :: Aggregate { sized : true } ,
781780 } ;
782781
783- if size == Size :: ZERO {
782+ if pref_pos . size == Size :: ZERO {
784783 // first non ZST: initialize 'abi'
785784 abi = field_abi;
786785 } else if abi != field_abi {
787786 // different fields have different ABI: reset to Aggregate
788787 abi = Abi :: Aggregate { sized : true } ;
789788 }
790789 }
791-
792- size = cmp:: max ( size, field. pref_pos . size ) ;
790+ pref_pos = pref_pos. max ( field. pref_pos ) ;
793791 }
794792
795793 if let Some ( pack) = def. repr . pack {
796- align = align . min ( AbiAndPrefAlign :: new ( pack) ) ;
794+ pref_pos = pref_pos . pack_to ( AbiAndPrefAlign :: new ( pack) ) ;
797795 }
798796
799- let pref_pos = LayoutPositionPref :: new ( size, align) . strided ( ) ;
797+ // preserve stride == size
798+ let pref_pos = pref_pos. strided ( ) ;
800799
801800 return Ok ( tcx. intern_layout ( LayoutDetails {
802801 variants : Variants :: Single { index } ,
0 commit comments