Missed niche optimization
Open
Nobody has claimed this yet.
A-layout
C-optimization
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
#[repr(u8)]
enum Foo {
A = 0,
}
#[repr(u8)]
enum Bar {
A = 1,
}
enum Choice {
F(Foo),
B(Bar),
}
fn main() {
dbg!(core::mem::size_of::<Choice>());
}
I expected to see this happen: Choice has size 1
Instead, this happened: Choice has size 2
Meta
Rust version; 1.74.1
@rustbot label A-layout T-compiler
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named. Start by compiling and running the provided Rust reproduction with Rust 1.74.1, confirming that core::mem::size_of::() is 2 instead of 1. Trace the compiler's enum layout and niche-optimization handling, and consider the issue done when an appropriate regression test demonstrates the expected size.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100