Skip to content

optimize enum of #[repr(int)] enums with non-overlapping discriminants to just use inner discriminant #126010

Closed as not planned
@programmerjake

Description

@programmerjake

currently this layout optimization is not done:

// could be size 2 since A and B's discriminants are in the same spot with non-overlapping contiguous values, but currently isn't
enum Top {
    A(A),
    B(B),
}

#[repr(u8)]
enum A {
    A0(u8) = 0,
    A1(u8) = 1,
}

#[repr(u8)]
enum B {
    B2(u8) = 2,
    B3(u8) = 3,
}

previously mentioned: #46213 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationA-layoutArea: Memory layout of typesC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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