@@ -2012,7 +2012,16 @@ impl CodeGenerator for CompInfo {
20122012 if let Some ( comment) = item. comment ( ctx) {
20132013 attributes. push ( attributes:: doc ( comment) ) ;
20142014 }
2015- if packed && !is_opaque {
2015+
2016+ let explicit_align = if ctx. options ( ) . rust_features ( ) . repr_align {
2017+ explicit_align
2018+ } else {
2019+ None
2020+ } ;
2021+
2022+ // We can't specify both packed(N) and align(N), but the packed()
2023+ // should be redundant in this case.
2024+ if packed && !is_opaque && explicit_align. is_none ( ) {
20162025 let n = layout. map_or ( 1 , |l| l. align ) ;
20172026 assert ! ( ctx. options( ) . rust_features( ) . repr_packed_n || n == 1 ) ;
20182027 let packed_repr = if n == 1 {
@@ -2025,17 +2034,13 @@ impl CodeGenerator for CompInfo {
20252034 attributes. push ( attributes:: repr ( "C" ) ) ;
20262035 }
20272036
2028- if ctx. options ( ) . rust_features ( ) . repr_align && !packed {
2029- // We can't specify both packed(N) and align(N), but the align()
2030- // should be redundant in this case.
2031- if let Some ( explicit) = explicit_align {
2032- // Ensure that the struct has the correct alignment even in
2033- // presence of alignas.
2034- let explicit = helpers:: ast_ty:: int_expr ( explicit as i64 ) ;
2035- attributes. push ( quote ! {
2036- #[ repr( align( #explicit) ) ]
2037- } ) ;
2038- }
2037+ if let Some ( explicit) = explicit_align {
2038+ // Ensure that the struct has the correct alignment even in
2039+ // presence of alignas.
2040+ let explicit = helpers:: ast_ty:: int_expr ( explicit as i64 ) ;
2041+ attributes. push ( quote ! {
2042+ #[ repr( align( #explicit) ) ]
2043+ } ) ;
20392044 }
20402045
20412046 let derivable_traits = derives_of_item ( item, ctx, packed) ;
0 commit comments