@@ -430,8 +430,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
430
430
( Some ( ( i, field) ) , None , None ) => {
431
431
// Field fills the struct and it has a scalar or scalar pair ABI.
432
432
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 ( ) {
435
434
match field. abi {
436
435
// For plain scalars, or vectors of them, we can't unpack
437
436
// newtypes for `#[repr(C)]`, as that affects C ABIs.
@@ -625,7 +624,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
625
624
tcx. intern_layout ( LayoutDetails {
626
625
variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
627
626
fields : FieldPlacement :: Array {
628
- stride : element. pref_pos . size ,
627
+ stride : element. pref_pos . stride ( ) ,
629
628
count
630
629
} ,
631
630
abi,
@@ -741,23 +740,23 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
741
740
bug ! ( "union cannot be packed and aligned" ) ;
742
741
}
743
742
744
- let mut align = if def. repr . pack . is_some ( ) {
743
+ let base_align = if def. repr . pack . is_some ( ) {
745
744
dl. i8_align
746
745
} else {
747
746
dl. aggregate_align
748
747
} ;
749
748
749
+ let mut pref_pos = LayoutPositionPref :: new ( Size :: ZERO , base_align) ;
750
+
750
751
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) ) ;
752
753
}
753
754
754
755
let optimize = !def. repr . inhibit_union_abi_opt ( ) ;
755
- let mut size = Size :: ZERO ;
756
756
let mut abi = Abi :: Aggregate { sized : true } ;
757
757
let index = VariantIdx :: new ( 0 ) ;
758
758
for field in & variants[ index] {
759
759
assert ! ( !field. is_unsized( ) ) ;
760
- align = align. max ( field. pref_pos . align ) ;
761
760
762
761
// If all non-ZST fields have the same ABI, forward this ABI
763
762
if optimize && !field. is_zst ( ) {
@@ -780,23 +779,23 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
780
779
Abi :: Aggregate { .. } => Abi :: Aggregate { sized : true } ,
781
780
} ;
782
781
783
- if size == Size :: ZERO {
782
+ if pref_pos . size == Size :: ZERO {
784
783
// first non ZST: initialize 'abi'
785
784
abi = field_abi;
786
785
} else if abi != field_abi {
787
786
// different fields have different ABI: reset to Aggregate
788
787
abi = Abi :: Aggregate { sized : true } ;
789
788
}
790
789
}
791
-
792
- size = cmp:: max ( size, field. pref_pos . size ) ;
790
+ pref_pos = pref_pos. max ( field. pref_pos ) ;
793
791
}
794
792
795
793
if let Some ( pack) = def. repr . pack {
796
- align = align . min ( AbiAndPrefAlign :: new ( pack) ) ;
794
+ pref_pos = pref_pos . pack_to ( AbiAndPrefAlign :: new ( pack) ) ;
797
795
}
798
796
799
- let pref_pos = LayoutPositionPref :: new ( size, align) . strided ( ) ;
797
+ // preserve stride == size
798
+ let pref_pos = pref_pos. strided ( ) ;
800
799
801
800
return Ok ( tcx. intern_layout ( LayoutDetails {
802
801
variants : Variants :: Single { index } ,
0 commit comments