Skip to content

Commit 5bf85fa

Browse files
committed
Add missing feature check
1 parent 5875601 commit 5bf85fa

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

src/codegen/mod.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,9 @@ 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 &&
2023+
explicit_align.is_some()
2024+
{
20232025
needs_packed_wrapper = true;
20242026
}
20252027
let packed_repr = if n == 1 || needs_packed_wrapper {
@@ -2030,13 +2032,16 @@ impl CodeGenerator for CompInfo {
20302032
attributes.push(attributes::repr_list(&["C", &packed_repr]));
20312033
} else {
20322034
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-
});
2035+
2036+
if ctx.options().rust_features().repr_align {
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+
});
2044+
}
20402045
}
20412046
}
20422047

@@ -2124,7 +2129,7 @@ impl CodeGenerator for CompInfo {
21242129
result.push(quote! {
21252130
#attributes
21262131
#[repr(C, align(#align))]
2127-
pub struct #canonical_ident(#layout_ident);
2132+
pub struct #canonical_ident(pub #layout_ident);
21282133
});
21292134
}
21302135

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)