-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Open
Labels
A-layoutArea: Memory layout of typesArea: Memory layout of typesC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
pub enum Outer {
A(Inner),
B(u32, u8),
}
pub enum Inner {
A(u32),
B(u32),
}
fn main() {
dbg!(std::mem::size_of::<Outer>());
}
I expected size_of::<Outer>()
to be 8
, indicating that rustc was able to "merge" the two enums:
Outer::A(Inner::A)
gets discriminant0
;Outer::B(Inner::B)
gets discriminant1
;Outer::B
gets discriminant2
;
Instead, size_of::<Outer>()
is 12
, indicating that no layout optimization was done.
Meta
$ rustc +nightly --version
rustc 1.92.0-nightly (fa3155a64 2025-09-30)
Metadata
Metadata
Assignees
Labels
A-layoutArea: Memory layout of typesArea: Memory layout of typesC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.