Open
Description
I tried this code:
use std::sync::atomic::AtomicU32;
#[repr(C, packed(4))]
struct Foo {
bar: AtomicU32,
}
I expected that #[repr(align(4))]
fields, such as AtomicU32
, would be allowed inside a #[repr(packed(4))]
struct, since the minimum alignment is >= the required alignment.
However, the compiler complains:
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
Use case: I have some fixed-layout shared memory structs I need to interact with, which sometimes contain unaligned u64s. I also need to use atomics on other parts of them (hopefully only u32s).
Meta
rustc --version --verbose
:
rustc 1.65.0-nightly (34a6cae28 2022-08-09)
binary: rustc
commit-hash: 34a6cae28e7013ff0e640026a8e46f315426829d
commit-date: 2022-08-09
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 14.0.6