-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-codegenArea: Code generationArea: Code generationA-enumArea: Enums (discriminated unions, or more generally ADTs (algebraic data types))Area: Enums (discriminated unions, or more generally ADTs (algebraic data types))A-reprArea: the `#[repr(stuff)]` attributeArea: the `#[repr(stuff)]` attributeA-type-systemArea: Type systemArea: Type systemC-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-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
The following code:
#[repr(u16)] enum Foo { A, B(u32, u16) }
println!("{}", std::mem::size_of::<Foo>());
currently outputs 12, but Foo
really only needs to take 8 bytes.
There are several alternatives which can correctly be packed into 8 bytes:
#[repr(u8)] enum Foo { A, B(u32, u16) }
#[repr(u16)] enum Foo { A, B(u16, u32) }
I see no reason why the first enum couldn't be packed into 8 bytes.
Metadata
Metadata
Assignees
Labels
A-codegenArea: Code generationArea: Code generationA-enumArea: Enums (discriminated unions, or more generally ADTs (algebraic data types))Area: Enums (discriminated unions, or more generally ADTs (algebraic data types))A-reprArea: the `#[repr(stuff)]` attributeArea: the `#[repr(stuff)]` attributeA-type-systemArea: Type systemArea: Type systemC-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-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.