Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upenum variants aren't considered to be const during const-evaluation #23898
Comments
pnkfelix
referenced this issue
Mar 31, 2015
Closed
enum variants aren't considered to be const #5873
pnkfelix
added
A-typesystem
P-medium
labels
Mar 31, 2015
This comment has been minimized.
This comment has been minimized.
|
(copied labels from #5873.) |
This comment has been minimized.
This comment has been minimized.
andersk
referenced this issue
Apr 8, 2015
Closed
Requires explicit discriminator value for every variant #1
andersk
added a commit
to andersk/enum_primitive-rs
that referenced
this issue
Apr 8, 2015
quantheory
referenced this issue
Jun 23, 2015
Merged
Fix ICE on recursively defined enum variant discriminant. #26515
This comment has been minimized.
This comment has been minimized.
|
This also seems to affect const fn. |
This comment has been minimized.
This comment has been minimized.
|
Would like to throw in my pennies and say that this makes doing a 1:1 port of C code into Rust (an otherwise relatively easy process) slightly annoying when the C code in question uses this trick. I have to calculate the length of the enum, define that as a const of the same name, and update it every time to the enum changes. |
pmarcelll
referenced this issue
Oct 4, 2016
Closed
Enum discriminants used as indices are subject to bounds checks #36955
kennytm
referenced this issue
Jan 6, 2017
Closed
"constant evaluation error" points to nothing when crossing the crate boundary #38875
This comment has been minimized.
This comment has been minimized.
|
For what it's worth, this does "work" in Rust 1.14 if you give values to the variants: use self::Category::*;
#[derive(Debug)]
enum Category {
A = 0,
B = 1,
C = 2,
NumCategories = 3,
}
const NUM_CATEGORIES: usize = NumCategories as usize;
fn main() {
let the_categories: [Category; NUM_CATEGORIES] = [A, B, C];
println!("{:?}", the_categories);
}However, it continues to fail if you cross the crate boundary (an example is available in #38875) |
This comment has been minimized.
This comment has been minimized.
|
It does seem odd and less-than-intuitive that implicit values and explicit values are treated differently, and that intra-crate and inter-crate are treated differently. |
pnkfelix commentedMar 31, 2015
Spawned off of #5873
playpen