Skip to content

Commit caa488b

Browse files
committed
Add tests
1 parent bd3a221 commit caa488b

File tree

5 files changed

+229
-1
lines changed

5 files changed

+229
-1
lines changed

tests/ui/never_patterns/check.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![feature(never_patterns)]
2+
#![allow(incomplete_features)]
3+
4+
enum Void {}
5+
6+
fn main() {}
7+
8+
macro_rules! never {
9+
() => { ! }
10+
}
11+
12+
fn no_arms_or_guards(x: Void) {
13+
match None::<Void> {
14+
Some(!) => {}
15+
None => {}
16+
}
17+
match None::<Void> {
18+
Some(!) if true,
19+
//~^ ERROR expected one of
20+
None => {}
21+
}
22+
match None::<Void> {
23+
Some(!) if true => {}
24+
None => {}
25+
}
26+
match None::<Void> {
27+
Some(never!()) => {},
28+
None => {}
29+
}
30+
}

tests/ui/never_patterns/check.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `.`, `=>`, `?`, or an operator, found `,`
2+
--> $DIR/check.rs:18:24
3+
|
4+
LL | Some(!) if true,
5+
| ^ expected one of `.`, `=>`, `?`, or an operator
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
macro_rules! pat {
2+
() => { Some(_) }
3+
}
4+
5+
fn main() {
6+
match Some(false) {
7+
Some(_)
8+
}
9+
//~^ ERROR expected one of
10+
match Some(false) {
11+
Some(_)
12+
_ => {}
13+
//~^ ERROR expected one of
14+
}
15+
match Some(false) {
16+
Some(_),
17+
//~^ ERROR unexpected `,` in pattern
18+
//~| HELP try adding parentheses to match on a tuple
19+
//~| HELP or a vertical bar to match on multiple alternatives
20+
}
21+
match Some(false) {
22+
Some(_),
23+
//~^ ERROR unexpected `,` in pattern
24+
//~| HELP try adding parentheses to match on a tuple
25+
//~| HELP or a vertical bar to match on multiple alternatives
26+
_ => {}
27+
}
28+
match Some(false) {
29+
Some(_) if true
30+
}
31+
//~^ ERROR expected one of
32+
match Some(false) {
33+
Some(_) if true
34+
_ => {}
35+
//~^ ERROR expected one of
36+
}
37+
match Some(false) {
38+
Some(_) if true,
39+
//~^ ERROR expected one of
40+
}
41+
match Some(false) {
42+
Some(_) if true,
43+
//~^ ERROR expected one of
44+
_ => {}
45+
}
46+
match Some(false) {
47+
pat!()
48+
}
49+
//~^ ERROR expected one of
50+
match Some(false) {
51+
pat!(),
52+
//~^ ERROR unexpected `,` in pattern
53+
}
54+
match Some(false) {
55+
pat!() if true,
56+
//~^ ERROR expected one of
57+
}
58+
match Some(false) {
59+
pat!()
60+
_ => {}
61+
//~^ ERROR expected one of
62+
}
63+
match Some(false) {
64+
pat!(),
65+
//~^ ERROR unexpected `,` in pattern
66+
_ => {}
67+
}
68+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
error: expected one of `=>`, `if`, or `|`, found `}`
2+
--> $DIR/match-arm-without-body.rs:8:5
3+
|
4+
LL | Some(_)
5+
| - expected one of `=>`, `if`, or `|`
6+
LL | }
7+
| ^ unexpected token
8+
9+
error: expected one of `=>`, `if`, or `|`, found reserved identifier `_`
10+
--> $DIR/match-arm-without-body.rs:12:9
11+
|
12+
LL | Some(_)
13+
| - expected one of `=>`, `if`, or `|`
14+
LL | _ => {}
15+
| ^ unexpected token
16+
17+
error: unexpected `,` in pattern
18+
--> $DIR/match-arm-without-body.rs:16:16
19+
|
20+
LL | Some(_),
21+
| ^
22+
|
23+
help: try adding parentheses to match on a tuple...
24+
|
25+
LL | (Some(_),)
26+
| + +
27+
help: ...or a vertical bar to match on multiple alternatives
28+
|
29+
LL | Some(_) |
30+
|
31+
32+
error: unexpected `,` in pattern
33+
--> $DIR/match-arm-without-body.rs:22:16
34+
|
35+
LL | Some(_),
36+
| ^
37+
|
38+
help: try adding parentheses to match on a tuple...
39+
|
40+
LL ~ (Some(_),
41+
LL |
42+
LL |
43+
LL |
44+
LL ~ _) => {}
45+
|
46+
help: ...or a vertical bar to match on multiple alternatives
47+
|
48+
LL ~ Some(_) |
49+
LL +
50+
LL +
51+
LL +
52+
LL ~ _ => {}
53+
|
54+
55+
error: expected one of `.`, `=>`, `?`, or an operator, found `}`
56+
--> $DIR/match-arm-without-body.rs:30:5
57+
|
58+
LL | Some(_) if true
59+
| - expected one of `.`, `=>`, `?`, or an operator
60+
LL | }
61+
| ^ unexpected token
62+
63+
error: expected one of `.`, `=>`, `?`, or an operator, found reserved identifier `_`
64+
--> $DIR/match-arm-without-body.rs:34:9
65+
|
66+
LL | Some(_) if true
67+
| - expected one of `.`, `=>`, `?`, or an operator
68+
LL | _ => {}
69+
| ^ unexpected token
70+
71+
error: expected one of `.`, `=>`, `?`, or an operator, found `,`
72+
--> $DIR/match-arm-without-body.rs:38:24
73+
|
74+
LL | Some(_) if true,
75+
| ^ expected one of `.`, `=>`, `?`, or an operator
76+
77+
error: expected one of `.`, `=>`, `?`, or an operator, found `,`
78+
--> $DIR/match-arm-without-body.rs:42:24
79+
|
80+
LL | Some(_) if true,
81+
| ^ expected one of `.`, `=>`, `?`, or an operator
82+
83+
error: expected one of `=>`, `if`, or `|`, found `}`
84+
--> $DIR/match-arm-without-body.rs:48:5
85+
|
86+
LL | pat!()
87+
| - expected one of `=>`, `if`, or `|`
88+
LL | }
89+
| ^ unexpected token
90+
91+
error: unexpected `,` in pattern
92+
--> $DIR/match-arm-without-body.rs:51:15
93+
|
94+
LL | pat!(),
95+
| ^
96+
|
97+
= note: macros cannot expand to match arms
98+
99+
error: expected one of `.`, `=>`, `?`, or an operator, found `,`
100+
--> $DIR/match-arm-without-body.rs:55:23
101+
|
102+
LL | pat!() if true,
103+
| ^ expected one of `.`, `=>`, `?`, or an operator
104+
105+
error: expected one of `=>`, `if`, or `|`, found reserved identifier `_`
106+
--> $DIR/match-arm-without-body.rs:60:9
107+
|
108+
LL | pat!()
109+
| - expected one of `=>`, `if`, or `|`
110+
LL | _ => {}
111+
| ^ unexpected token
112+
113+
error: unexpected `,` in pattern
114+
--> $DIR/match-arm-without-body.rs:64:15
115+
|
116+
LL | pat!(),
117+
| ^
118+
|
119+
= note: macros cannot expand to match arms
120+
121+
error: aborting due to 13 previous errors
122+

tests/ui/pattern/never_patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn never_and_bindings() {
8484
//~^ ERROR: is not bound in all patterns
8585
}
8686
let (Ok(_x) | Err(&!)) = x;
87-
//~^ ERROR: is not bound in all patterns
87+
//~^ ERROR: is not bound in all patterns
8888

8989
// FIXME(never_patterns): A never pattern mustn't have bindings.
9090
match x {

0 commit comments

Comments
 (0)