@@ -273,14 +273,12 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
273
273
repr : & ReprOptions ,
274
274
kind : StructKind ) -> Result < LayoutDetails , LayoutError < ' tcx > > {
275
275
let dl = self . data_layout ( ) ;
276
- let packed = repr. packed ( ) ;
277
- if packed && repr. align > 0 {
276
+ let pack = repr. pack ;
277
+ if pack . is_some ( ) && repr. align . is_some ( ) {
278
278
bug ! ( "struct cannot be packed and aligned" ) ;
279
279
}
280
280
281
- let pack = Align :: from_bytes ( repr. pack as u64 ) . unwrap ( ) ;
282
-
283
- let mut align = if packed {
281
+ let mut align = if pack. is_some ( ) {
284
282
dl. i8_align
285
283
} else {
286
284
dl. aggregate_align
@@ -303,7 +301,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
303
301
} ;
304
302
let optimizing = & mut inverse_memory_index[ ..end] ;
305
303
let field_align = |f : & TyLayout < ' _ > | {
306
- if packed { f. align . abi . min ( pack) } else { f. align . abi }
304
+ if let Some ( pack ) = pack { f. align . abi . min ( pack) } else { f. align . abi }
307
305
} ;
308
306
match kind {
309
307
StructKind :: AlwaysSized |
@@ -334,7 +332,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
334
332
let mut largest_niche_available = 0 ;
335
333
336
334
if let StructKind :: Prefixed ( prefix_size, prefix_align) = kind {
337
- let prefix_align = if packed {
335
+ let prefix_align = if let Some ( pack ) = pack {
338
336
prefix_align. min ( pack)
339
337
} else {
340
338
prefix_align
@@ -355,7 +353,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
355
353
}
356
354
357
355
// Invariant: offset < dl.obj_size_bound() <= 1<<61
358
- let field_align = if packed {
356
+ let field_align = if let Some ( pack ) = pack {
359
357
field. align . min ( AbiAndPrefAlign :: new ( pack) )
360
358
} else {
361
359
field. align
@@ -379,10 +377,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
379
377
. ok_or ( LayoutError :: SizeOverflow ( ty) ) ?;
380
378
}
381
379
382
- if repr. align > 0 {
383
- let repr_align = repr. align as u64 ;
384
- align = align. max ( AbiAndPrefAlign :: new ( Align :: from_bytes ( repr_align) . unwrap ( ) ) ) ;
385
- debug ! ( "univariant repr_align: {:?}" , repr_align) ;
380
+ if let Some ( repr_align) = repr. align {
381
+ align = align. max ( AbiAndPrefAlign :: new ( repr_align) ) ;
386
382
}
387
383
388
384
debug ! ( "univariant min_size: {:?}" , offset) ;
@@ -730,23 +726,18 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
730
726
} ) . collect :: < Result < IndexVec < VariantIdx , _ > , _ > > ( ) ?;
731
727
732
728
if def. is_union ( ) {
733
- let packed = def. repr . packed ( ) ;
734
- if packed && def. repr . align > 0 {
735
- bug ! ( "Union cannot be packed and aligned" ) ;
729
+ if def. repr . pack . is_some ( ) && def. repr . align . is_some ( ) {
730
+ bug ! ( "union cannot be packed and aligned" ) ;
736
731
}
737
732
738
- let pack = Align :: from_bytes ( def. repr . pack as u64 ) . unwrap ( ) ;
739
-
740
- let mut align = if packed {
733
+ let mut align = if def. repr . pack . is_some ( ) {
741
734
dl. i8_align
742
735
} else {
743
736
dl. aggregate_align
744
737
} ;
745
738
746
- if def. repr . align > 0 {
747
- let repr_align = def. repr . align as u64 ;
748
- align = align. max (
749
- AbiAndPrefAlign :: new ( Align :: from_bytes ( repr_align) . unwrap ( ) ) ) ;
739
+ if let Some ( repr_align) = def. repr . align {
740
+ align = align. max ( AbiAndPrefAlign :: new ( repr_align) ) ;
750
741
}
751
742
752
743
let optimize = !def. repr . inhibit_union_abi_opt ( ) ;
@@ -755,13 +746,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
755
746
let index = VariantIdx :: new ( 0 ) ;
756
747
for field in & variants[ index] {
757
748
assert ! ( !field. is_unsized( ) ) ;
758
-
759
- let field_align = if packed {
760
- field. align . min ( AbiAndPrefAlign :: new ( pack) )
761
- } else {
762
- field. align
763
- } ;
764
- align = align. max ( field_align) ;
749
+ align = align. max ( field. align ) ;
765
750
766
751
// If all non-ZST fields have the same ABI, forward this ABI
767
752
if optimize && !field. is_zst ( ) {
@@ -796,6 +781,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
796
781
size = cmp:: max ( size, field. size ) ;
797
782
}
798
783
784
+ if let Some ( pack) = def. repr . pack {
785
+ align = align. min ( AbiAndPrefAlign :: new ( pack) ) ;
786
+ }
787
+
799
788
return Ok ( tcx. intern_layout ( LayoutDetails {
800
789
variants : Variants :: Single { index } ,
801
790
fields : FieldPlacement :: Union ( variants[ index] . len ( ) ) ,
@@ -1637,7 +1626,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1637
1626
} ;
1638
1627
1639
1628
let adt_kind = adt_def. adt_kind ( ) ;
1640
- let adt_packed = adt_def. repr . packed ( ) ;
1629
+ let adt_packed = adt_def. repr . pack . is_some ( ) ;
1641
1630
1642
1631
let build_variant_info = |n : Option < Ident > ,
1643
1632
flds : & [ ast:: Name ] ,
0 commit comments