Skip to content

enum variants aren't considered to be const during const-evaluation #23898

Closed
@pnkfelix

Description

@pnkfelix

Spawned off of #5873

use self::Category::*;

enum Category {
    A,
    B,
    C,
    NumCategories,
}
const NUM_CATEGORIES: usize = NumCategories as usize;

fn main() {
    let the_categories: [Category; NUM_CATEGORIES] = [A, B, C];
    println!("{:?}", the_categories);
}

playpen

<anon>:9:31: 9:44 error: array length constant evaluation error: non-constant path in constant expr [E0250]
<anon>:9 const NUM_CATEGORIES: usize = NumCategories as usize;
                                       ^~~~~~~~~~~~~
<anon>:12:25: 12:51 note: for array length here
<anon>:12     let the_categories: [Category; NUM_CATEGORIES] = [A, B, C];
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions