Enum inside enum optimization allows only one "inner" variant
Open
Nobody has claimed this yet.
A-enum
C-bug
C-optimization
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
enum Inner {
A(u32),
B(u32),
}
enum Outer {
C(u32),
D(Inner),
// Adding this variant increases size_of from 8 to 12
E(Inner),
}
fn main() {
dbg!(size_of::<Outer>());
}
I expected to see this happen:
size_of::<Outer>() = 8
Instead, this happened:
size_of::<Outer>() = 12
Meta
rustc --version:
1.98.1 (48a229cea 2026-09-01)
1.100.0-nightly (2026-09-12 809936eac66c547a5127)
Making Outer enum 8-byte long would speed up wasmtime:
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
Start by compiling the minimal enum example and checking its reported size on the stable and nightly versions listed in the issue. Then inspect the referenced Wasmtime enum definitions in crates/environ/src/types.rs at lines 461-471 and 344-357, and trace the compiler's enum layout handling. Done means the reproducer achieves the expected 8-byte size without regressing relevant layout behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100