Skip to content

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

@kmcallister

Description

@kmcallister
#[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;  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions