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 discriminant 0;
Outer::B(Inner::B) gets discriminant 1;
Outer::B gets discriminant 2;
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)
I tried this code:
I expected
size_of::<Outer>()to be8, indicating that rustc was able to "merge" the two enums:Outer::A(Inner::A)gets discriminant0;Outer::B(Inner::B)gets discriminant1;Outer::Bgets discriminant2;Instead,
size_of::<Outer>()is12, indicating that no layout optimization was done.Meta