Skip to content

Commit bed1897

Browse files
committed
type-alias-enum-variants-panic: harden + describe the test.
1 parent 77ff384 commit bed1897

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
// ignore-tidy-linelength
22

3+
// Check that creating/matching on an enum variant through an alias with
4+
// the wrong braced/unit form is caught as an error.
5+
36
#![allow(unreachable_code)]
47

5-
enum Enum { Variant {} }
8+
enum Enum { Braced {}, Unit, Tuple() }
69
type Alias = Enum;
710

811
fn main() {
9-
Alias::Variant;
10-
//~^ ERROR expected unit struct/variant or constant, found struct variant `<Alias>::Variant` [E0533]
11-
let Alias::Variant = panic!();
12-
//~^ ERROR expected unit struct/variant or constant, found struct variant `<Alias>::Variant` [E0533]
13-
let Alias::Variant(..) = panic!();
14-
//~^ ERROR expected tuple struct/variant, found struct variant `<Alias>::Variant` [E0164]
12+
Alias::Braced;
13+
//~^ ERROR expected unit struct/variant or constant, found struct variant `<Alias>::Braced` [E0533]
14+
let Alias::Braced = panic!();
15+
//~^ ERROR expected unit struct/variant or constant, found struct variant `<Alias>::Braced` [E0533]
16+
let Alias::Braced(..) = panic!();
17+
//~^ ERROR expected tuple struct/variant, found struct variant `<Alias>::Braced` [E0164]
18+
19+
Alias::Unit();
20+
//~^ ERROR expected function, found enum variant `<Alias>::Unit`
21+
let Alias::Unit() = panic!();
22+
//~^ ERROR expected tuple struct/variant, found unit variant `<Alias>::Unit` [E0164]
1523
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
1-
error[E0533]: expected unit struct/variant or constant, found struct variant `<Alias>::Variant`
2-
--> $DIR/type-alias-enum-variants-panic.rs:9:5
1+
error[E0533]: expected unit struct/variant or constant, found struct variant `<Alias>::Braced`
2+
--> $DIR/type-alias-enum-variants-panic.rs:12:5
33
|
4-
LL | Alias::Variant;
5-
| ^^^^^^^^^^^^^^
4+
LL | Alias::Braced;
5+
| ^^^^^^^^^^^^^
66

7-
error[E0533]: expected unit struct/variant or constant, found struct variant `<Alias>::Variant`
8-
--> $DIR/type-alias-enum-variants-panic.rs:11:9
7+
error[E0533]: expected unit struct/variant or constant, found struct variant `<Alias>::Braced`
8+
--> $DIR/type-alias-enum-variants-panic.rs:14:9
99
|
10-
LL | let Alias::Variant = panic!();
11-
| ^^^^^^^^^^^^^^
10+
LL | let Alias::Braced = panic!();
11+
| ^^^^^^^^^^^^^
1212

13-
error[E0164]: expected tuple struct/variant, found struct variant `<Alias>::Variant`
14-
--> $DIR/type-alias-enum-variants-panic.rs:13:9
13+
error[E0164]: expected tuple struct/variant, found struct variant `<Alias>::Braced`
14+
--> $DIR/type-alias-enum-variants-panic.rs:16:9
1515
|
16-
LL | let Alias::Variant(..) = panic!();
17-
| ^^^^^^^^^^^^^^^^^^ not a tuple variant or struct
16+
LL | let Alias::Braced(..) = panic!();
17+
| ^^^^^^^^^^^^^^^^^ not a tuple variant or struct
1818

19-
error: aborting due to 3 previous errors
19+
error[E0618]: expected function, found enum variant `<Alias>::Unit`
20+
--> $DIR/type-alias-enum-variants-panic.rs:19:5
21+
|
22+
LL | enum Enum { Braced {}, Unit, Tuple() }
23+
| ---- `<Alias>::Unit` defined here
24+
...
25+
LL | Alias::Unit();
26+
| ^^^^^^^^^^^--
27+
| |
28+
| call expression requires function
29+
help: `<Alias>::Unit` is a unit variant, you need to write it without the parenthesis
30+
|
31+
LL | <Alias>::Unit;
32+
| ^^^^^^^^^^^^^
33+
34+
error[E0164]: expected tuple struct/variant, found unit variant `<Alias>::Unit`
35+
--> $DIR/type-alias-enum-variants-panic.rs:21:9
36+
|
37+
LL | let Alias::Unit() = panic!();
38+
| ^^^^^^^^^^^^^ not a tuple variant or struct
39+
40+
error: aborting due to 5 previous errors
2041

21-
For more information about this error, try `rustc --explain E0164`.
42+
Some errors have detailed explanations: E0164, E0618.
43+
For more information about an error, try `rustc --explain E0164`.

0 commit comments

Comments
 (0)