@@ -1133,15 +1133,16 @@ enum Bad {
1133
1133
}
1134
1134
```
1135
1135
1136
- Here `X` will have already been assigned the discriminant 0 by the time `Y` is
1136
+ Here `X` will have already been specified the discriminant 0 by the time `Y` is
1137
1137
encountered, so a conflict occurs.
1138
1138
"## ,
1139
1139
1140
1140
E0082 : r##"
1141
- The default type for enum discriminants is `isize`, but it can be adjusted by
1142
- adding the `repr` attribute to the enum declaration. This error indicates that
1143
- an integer literal given as a discriminant is not a member of the discriminant
1144
- type. For example:
1141
+ When you specify enum discriminants with `=`, the compiler expects `isize`
1142
+ values by default. Or you can add the `repr` attibute to the enum declaration
1143
+ for an explicit choice of the discriminant type. In either cases, the
1144
+ discriminant values must fall within a valid range for the expected type;
1145
+ otherwise this error is raised. For example:
1145
1146
1146
1147
```compile_fail
1147
1148
#[repr(u8)]
@@ -1152,11 +1153,19 @@ enum Thing {
1152
1153
```
1153
1154
1154
1155
Here, 1024 lies outside the valid range for `u8`, so the discriminant for `A` is
1155
- invalid. You may want to change representation types to fix this, or else change
1156
- invalid discriminant values so that they fit within the existing type.
1156
+ invalid. Here is another, more subtle example which depends on target word size:
1157
1157
1158
- Note also that without a representation manually defined, the compiler will
1159
- optimize by using the smallest integer type possible.
1158
+ ```compile_fail
1159
+ enum DependsOnPointerSize {
1160
+ A = 1 << 32
1161
+ }
1162
+ ```
1163
+
1164
+ Here, `1 << 32` is interpreted as an `isize` value. So it is invalid for 32 bit
1165
+ target (`target_pointer_width = "32"`) but valid for 64 bit target.
1166
+
1167
+ You may want to change representation types to fix this, or else change invalid
1168
+ discriminant values so that they fit within the existing type.
1160
1169
"## ,
1161
1170
1162
1171
E0084 : r##"
0 commit comments