Skip to content

Can't use "enum as u8" in constexpr #18153

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

Closed
kmcallister opened this issue Oct 19, 2014 · 2 comments
Closed

Can't use "enum as u8" in constexpr #18153

kmcallister opened this issue Oct 19, 2014 · 2 comments

Comments

@kmcallister
Copy link
Contributor

#[repr(u8)]
enum Tag {
    Dynamic,
    Inline,
    Static,
}

pub const DYNAMIC_TAG: u8 = Dynamic as u8;
pub const INLINE_TAG: u8 = Inline as u8;
pub const STATIC_TAG: u8 = Static as u8;

produces

/home/keegan/string-cache/shared/repr.rs:23:29: 23:42 error: non-constant path in constant expr  
/home/keegan/string-cache/shared/repr.rs:23 pub const DYNAMIC_TAG: u8 = Dynamic as u8;  
@mahkoh
Copy link
Contributor

mahkoh commented Oct 19, 2014

This is part of rust-lang/rfcs#259. Note that this works if you explicitly specify the values.

@huonw
Copy link
Member

huonw commented Oct 19, 2014

Dupe of #5873.

@huonw huonw closed this as completed Oct 19, 2014
lnicola pushed a commit to lnicola/rust that referenced this issue Sep 25, 2024
fix: When checking for forbidden expr kind matches, account for rawness

An expression starting with `r#const` etc. should be accepted even in edition <=2021.

Fixes rust-lang#18148.

This was not fixed when testing with edition 2024, I wonder whether that means our check for edition is incorrect...
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

No branches or pull requests

3 participants