Skip to content

Missed niche optimization #119055

Open
Open
@Jules-Bertholet

Description

@Jules-Bertholet

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layoutArea: Memory layout of typesC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions