Skip to content

Commit dfa0d2c

Browse files
Improve E0084 error explanation
1 parent 487de42 commit dfa0d2c

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,12 +1193,32 @@ discriminant values so that they fit within the existing type.
11931193
"##,
11941194

11951195
E0084: r##"
1196+
An unsupported representation was attempted on a zero-variant enum.
1197+
1198+
Erroneous code example:
1199+
1200+
```compile_fail
1201+
#[repr(i32)]
1202+
enum NightWatch {} // error: unsupported representation for zero-variant enum
1203+
```
1204+
11961205
It is impossible to define an integer type to be used to represent zero-variant
11971206
enum values because there are no zero-variant enum values. There is no way to
1198-
construct an instance of the following type using only safe code:
1207+
construct an instance of the following type using only safe code. So you have
1208+
two solutions. Either you add variants in your enum:
1209+
1210+
```
1211+
#[repr(i32)]
1212+
enum NightWatch {
1213+
JohnSnow,
1214+
Commander,
1215+
}
1216+
```
1217+
1218+
or you remove the integer represention of your enum:
11991219
12001220
```
1201-
enum Empty {}
1221+
enum NightWatch {}
12021222
```
12031223
"##,
12041224

0 commit comments

Comments
 (0)