Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choose enum discriminant type based on repr attributes, suffixes, values #196

Merged
merged 17 commits into from
May 11, 2020

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented May 11, 2020

Fixes #175.

In order, the choice of repr is based on:

  • #[repr(...)] attribute

    #[repr(u16)]
    enum E {  //:u16
        A,
        B,
    }
  • otherwise, integer suffix

    enum E {  //:isize
        A = 0isize,
        B,
    }
  • otherwise, range of discriminant values

    The first of u8, i8, u16, i16, u32, i32, u64, i64 that can fit all of the values.

    enum E {  //:i16
        A = -1,
        B = 2020,
    }

FYI @jgalenson

@dtolnay dtolnay merged commit a954fca into master May 11, 2020
@dtolnay dtolnay deleted the enum branch May 11, 2020 07:14
@jgalenson
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Represent enums using the smallest sufficient integer type
2 participants