Skip to content

Commit

Permalink
try to avoid #[repr(packed)] when align is needed
Browse files Browse the repository at this point in the history
Currently rustc forbids compound types from having both a `packed` and
`align` attribute.

When a source type has both attributes, this may mean it cannot be
represented with the current rustc. Often, though, one or both of these
attributes is redundant and can be safely removed from the generated
Rust code.

Previously, bindgen avoided placing the `align` attribute when it is
not needed. However, it would always place the `packed` attribute if the
source type has it, even when it is redundant because the source type is
"naturally packed".

With this change, bindgen avoids placing `packed` on a type if the
`packed` is redundant and the type needs an `align` attribute. If the
type does not have an "align" attribute, then bindgen will still place
`packed` so as to avoid changing existing working behavior.
  • Loading branch information
bertschingert committed Jan 26, 2024
1 parent 3370a3c commit 5df4ef5
Show file tree
Hide file tree
Showing 4 changed files with 441 additions and 1 deletion.
369 changes: 369 additions & 0 deletions bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5df4ef5

Please sign in to comment.