gccrs
gccrs copied to clipboard
Disallow discriminant variants in enums with tuples or structs
I tried this code:
enum WithVariants {
Discri = 1,
Simple,
Tuple(i32),
Structure { a: i32, b: i32 },
}
I expected to see this happen: rustc errors out with the following message
error[E0658]: custom discriminant values are not allowed in enums with tuple or struct variants
--> test.rs:2:14
|
2 | Discri = 1,
| ^ disallowed custom discriminant
3 | Simple,
4 | Tuple(i32),
| ---------- tuple variant defined here
5 | Structure { a: i32, b: i32 },
| ---------------------------- struct variant defined here
|
Instead, this happened: The code compiled fine
I never realised this was an error case, I tried to put code in to make this work but kept having the conclusion that it wouldn't work. Great find.
Isn't there an unstable feature that allows this?
Isn't there an unstable feature that allows this?
Oh fair point I didn't think of checking. I found arbitrary_enum_discriminant which implements it on top of adding discriminants to tuple and struct variants.
I think this is something that we can think about after implementing the stable behavior.