You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
support explicit discriminant numbers on tag variants #1393
Currently tags always use 0 ... N, where N is the number of tag variants, as the discriminant values.
This makes them useless for modeling C enums, which they are the natural analogue of. We should support a form of variant-declarator that provides a discriminant value, as (say) an uint const expression or something.
Ideal sort of example:
tag color {
red = 0xff;
blue = 0xfe;
}
It'd also be nice to be able to cast back and forth against uint values, and similar "like in C" enum tricks. But one thing at a time.
I'm not sure on the value of having both data and discriminant values, and even less sure on the syntax, for now I'll disallow it by not supporting the syntax for it.
Also, my patch does increase by 1 when not specified just like the C enum does as it is trivial to implement.
Activity
kevina commentedon Dec 29, 2011
I'll look into this. Expect something in the next couple of days.
graydon commentedon Dec 30, 2011
see Issue #1397.
nikomatsakis commentedon Dec 30, 2011
Should it be legal to have both associated data and an explicit discriminant value?
nikomatsakis commentedon Dec 30, 2011
My opinion: why not? Also, the discriminant value ought to increase by 1 from the previous discriminant, just as in an enum. So:
tag t {
a = 1; // discriminant == 1
b = 10; // discriminant == 10
c(uint); // discriminant == 11
d(uint) = 15; // discriminant == 15
}
kevina commentedon Dec 31, 2011
I'm not sure on the value of having both data and discriminant values, and even less sure on the syntax, for now I'll disallow it by not supporting the syntax for it.
Also, my patch does increase by 1 when not specified just like the C enum does as it is trivial to implement.
Support explicit discriminant numbers on tag variants.
Cleanups to previous commits for issue rust-lang#1393.
Cleanups to previous commits for issue #1393.
brson commentedon Jan 24, 2012
@kevina - This is done?
brson commentedon Jan 24, 2012
I'm told it's as done as it's going to get. Yay!
Merge pull request rust-lang#1393 from onur-ozkan/rustfmt-group-imports
Merge rust-lang#1393
Auto merge of rust-lang#1393 - RalfJung:arg-count-cleanup, r=RalfJung