Skip to content

Commit 2f67f2a

Browse files
committed
Add missing feature check
1 parent 5875601 commit 2f67f2a

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

src/codegen/mod.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,7 @@ impl CodeGenerator for CompInfo {
20192019
if packed && !is_opaque {
20202020
let n = layout.map_or(1, |l| l.align);
20212021
assert!(ctx.options().rust_features().repr_packed_n || n == 1);
2022-
if explicit_align.is_some() {
2022+
if ctx.options().rust_features().repr_align && explicit_align.is_some() {
20232023
needs_packed_wrapper = true;
20242024
}
20252025
let packed_repr = if n == 1 || needs_packed_wrapper {
@@ -2030,13 +2030,16 @@ impl CodeGenerator for CompInfo {
20302030
attributes.push(attributes::repr_list(&["C", &packed_repr]));
20312031
} else {
20322032
attributes.push(attributes::repr("C"));
2033-
if let Some(explicit) = explicit_align {
2034-
// Ensure that the struct has the correct alignment even in
2035-
// presence of alignas.
2036-
let explicit = helpers::ast_ty::int_expr(explicit as i64);
2037-
attributes.push(quote! {
2038-
#[repr(align(#explicit))]
2039-
});
2033+
2034+
if ctx.options().rust_features().repr_align {
2035+
if let Some(explicit) = explicit_align {
2036+
// Ensure that the struct has the correct alignment even in
2037+
// presence of alignas.
2038+
let explicit = helpers::ast_ty::int_expr(explicit as i64);
2039+
attributes.push(quote! {
2040+
#[repr(align(#explicit))]
2041+
});
2042+
}
20402043
}
20412044
}
20422045

@@ -2124,7 +2127,7 @@ impl CodeGenerator for CompInfo {
21242127
result.push(quote! {
21252128
#attributes
21262129
#[repr(C, align(#align))]
2127-
pub struct #canonical_ident(#layout_ident);
2130+
pub struct #canonical_ident(pub #layout_ident);
21282131
});
21292132
}
21302133

tests/expectations/tests/issue-537-repr-packed-n.rs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/expectations/tests/issue-537.rs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/expectations/tests/packed-align-conflict.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/expectations/tests/packed-n-with-padding.rs

Lines changed: 3 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)