@@ -2012,7 +2012,16 @@ impl CodeGenerator for CompInfo {
2012
2012
if let Some ( comment) = item. comment ( ctx) {
2013
2013
attributes. push ( attributes:: doc ( comment) ) ;
2014
2014
}
2015
- if packed && !is_opaque {
2015
+
2016
+ // We can't specify both packed(N) and align(N), but the align()
2017
+ // should be redundant in this case.
2018
+ let explicit_align = if ctx. options ( ) . rust_features ( ) . repr_align {
2019
+ explicit_align
2020
+ } else {
2021
+ None
2022
+ } ;
2023
+
2024
+ if packed && !is_opaque && explicit_align. is_none ( ) {
2016
2025
let n = layout. map_or ( 1 , |l| l. align ) ;
2017
2026
assert ! ( ctx. options( ) . rust_features( ) . repr_packed_n || n == 1 ) ;
2018
2027
let packed_repr = if n == 1 {
@@ -2025,17 +2034,13 @@ impl CodeGenerator for CompInfo {
2025
2034
attributes. push ( attributes:: repr ( "C" ) ) ;
2026
2035
}
2027
2036
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
+ } ) ;
2039
2044
}
2040
2045
2041
2046
let derivable_traits = derives_of_item ( item, ctx, packed) ;
0 commit comments