-
Couldn't load subscription status.
- Fork 13.9k
Open
Labels
A-enumArea: Enums (discriminated unions, or more generally ADTs (algebraic data types))Area: Enums (discriminated unions, or more generally ADTs (algebraic data types))A-layoutArea: Memory layout of typesArea: Memory layout of typesC-bugCategory: This is a bug.Category: This is a bug.T-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.T-langRelevant to the language teamRelevant to the language team
Description
I tried this code:
#[derive(Clone, Copy)]
enum Never {}
#[repr(u32)]
enum MyEnum {
A(Never),
B(Never),
}
#[repr(C)]
union MyEnumRepr {
A: MyVariantA,
B: MyVariantB,
}
#[repr(u32)]
#[derive(Copy, Clone)]
enum MyEnumDiscriminant { A, B }
#[repr(C)]
#[derive(Clone, Copy)]
struct MyVariantA(MyEnumDiscriminant, Never);
#[repr(C)]
#[derive(Clone, Copy)]
struct MyVariantB(MyEnumDiscriminant, Never);
fn main() {
println!("{}", size_of::<MyEnum>());
println!("{}", size_of::<MyEnumRepr>());
}I expected MyEnum and MyEnumRepr to have the same size, since this is the desugaring given as an example in the reference.
Instead, MyEnum has size 0, while MyEnumRepr has size 4.
Discovered by masterjason9637 on the rust community discord.
Meta
Reproducible on the playground with version 1.92.0-nightly (2025-09-23 975e6c8fec280816d24f)
Metadata
Metadata
Assignees
Labels
A-enumArea: Enums (discriminated unions, or more generally ADTs (algebraic data types))Area: Enums (discriminated unions, or more generally ADTs (algebraic data types))A-layoutArea: Memory layout of typesArea: Memory layout of typesC-bugCategory: This is a bug.Category: This is a bug.T-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.T-langRelevant to the language teamRelevant to the language team