@@ -273,14 +273,12 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
273273 repr : & ReprOptions ,
274274 kind : StructKind ) -> Result < LayoutDetails , LayoutError < ' tcx > > {
275275 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 ( ) {
278278 bug ! ( "struct cannot be packed and aligned" ) ;
279279 }
280280
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 ( ) {
284282 dl. i8_align
285283 } else {
286284 dl. aggregate_align
@@ -303,7 +301,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
303301 } ;
304302 let optimizing = & mut inverse_memory_index[ ..end] ;
305303 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 }
307305 } ;
308306 match kind {
309307 StructKind :: AlwaysSized |
@@ -334,7 +332,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
334332 let mut largest_niche_available = 0 ;
335333
336334 if let StructKind :: Prefixed ( prefix_size, prefix_align) = kind {
337- let prefix_align = if packed {
335+ let prefix_align = if let Some ( pack ) = pack {
338336 prefix_align. min ( pack)
339337 } else {
340338 prefix_align
@@ -355,7 +353,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
355353 }
356354
357355 // Invariant: offset < dl.obj_size_bound() <= 1<<61
358- let field_align = if packed {
356+ let field_align = if let Some ( pack ) = pack {
359357 field. align . min ( AbiAndPrefAlign :: new ( pack) )
360358 } else {
361359 field. align
@@ -379,10 +377,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
379377 . ok_or ( LayoutError :: SizeOverflow ( ty) ) ?;
380378 }
381379
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) ) ;
386382 }
387383
388384 debug ! ( "univariant min_size: {:?}" , offset) ;
@@ -730,23 +726,18 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
730726 } ) . collect :: < Result < IndexVec < VariantIdx , _ > , _ > > ( ) ?;
731727
732728 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" ) ;
736731 }
737732
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 ( ) {
741734 dl. i8_align
742735 } else {
743736 dl. aggregate_align
744737 } ;
745738
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) ) ;
750741 }
751742
752743 let optimize = !def. repr . inhibit_union_abi_opt ( ) ;
@@ -755,13 +746,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
755746 let index = VariantIdx :: new ( 0 ) ;
756747 for field in & variants[ index] {
757748 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 ) ;
765750
766751 // If all non-ZST fields have the same ABI, forward this ABI
767752 if optimize && !field. is_zst ( ) {
@@ -796,6 +781,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
796781 size = cmp:: max ( size, field. size ) ;
797782 }
798783
784+ if let Some ( pack) = def. repr . pack {
785+ align = align. min ( AbiAndPrefAlign :: new ( pack) ) ;
786+ }
787+
799788 return Ok ( tcx. intern_layout ( LayoutDetails {
800789 variants : Variants :: Single { index } ,
801790 fields : FieldPlacement :: Union ( variants[ index] . len ( ) ) ,
@@ -1637,7 +1626,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
16371626 } ;
16381627
16391628 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 ( ) ;
16411630
16421631 let build_variant_info = |n : Option < Ident > ,
16431632 flds : & [ ast:: Name ] ,
0 commit comments