Skip to content

Commit c809a95

Browse files
committed
Add final description of enum treatment
1 parent 8dad941 commit c809a95

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

active/0000-rm-integer-fallback.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,21 @@ Finally, inference for `as` will be modified to track the types
4444
a value is being cast *to* for cases where the value being cast
4545
is unconstrained, like `0 as u8`.
4646

47+
Treatment of enum discriminants will need to change:
48+
49+
```
50+
enum Color { Red = 0, Green = 1, Blue = 2 }
51+
```
52+
53+
Currently, an unsuffixed integer defaults to `int`. Instead, we will
54+
only require enum descriminants primitive integers of unspecified
55+
type; assigning an integer to an enum will behave as if casting from
56+
from the type of the integer to an unsigned integer with the size of
57+
the enum discriminant.
58+
4759
# Drawbacks
4860

49-
This will force users to cast somewhat more often. In particular,
61+
This will force users to type hint somewhat more often. In particular,
5062
ranges of unsigned ints may need to be type-hinted:
5163

5264
```
@@ -61,13 +73,3 @@ Do none of this.
6173

6274
* If we're putting new restrictions on shift operators, should we
6375
change the traits, or just make the primitives special?
64-
65-
There is some question about how to treat enum discriminants:
66-
67-
```
68-
enum Color { Red = 0, Green = 1, Blue = 2 }
69-
```
70-
71-
Currently these default to `int`, but we need to change the
72-
behavior. Niko suggests just making discriminants always `int`, but
73-
how does that interact with `repr`?

0 commit comments

Comments
 (0)