-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-alignArea: alignment control (`repr(align(N))` and so on)Area: alignment control (`repr(align(N))` and so on)A-layoutArea: Memory layout of typesArea: Memory layout of typesA-reprArea: the `#[repr(stuff)]` attributeArea: the `#[repr(stuff)]` attributeA-repr-packedArea: the naughtiest reprArea: the naughtiest reprC-bugCategory: This is a bug.Category: This is a bug.O-windows-msvcToolchain: MSVC, Operating system: WindowsToolchain: MSVC, Operating system: Windows
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
DianaNitesdioguerra
Metadata
Metadata
Assignees
Labels
A-alignArea: alignment control (`repr(align(N))` and so on)Area: alignment control (`repr(align(N))` and so on)A-layoutArea: Memory layout of typesArea: Memory layout of typesA-reprArea: the `#[repr(stuff)]` attributeArea: the `#[repr(stuff)]` attributeA-repr-packedArea: the naughtiest reprArea: the naughtiest reprC-bugCategory: This is a bug.Category: This is a bug.O-windows-msvcToolchain: MSVC, Operating system: WindowsToolchain: MSVC, Operating system: Windows