Skip to content

Commit 8e7d070

Browse files
committed
Add test for parens around match arm pattern and condition
1 parent 1c6bd0b commit 8e7d070

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fn main() {
2+
let val = 42;
3+
let x = match val {
4+
(0 if true) => {
5+
//~^ ERROR expected identifier, found keyword `if`
6+
//~| ERROR expected one of `)`, `,`, `...`, `..=`, `..`, or `|`, found keyword `if`
7+
//~| ERROR expected one of `)`, `,`, `@`, or `|`, found keyword `true`
8+
//~| ERROR mismatched types
9+
42u8
10+
}
11+
_ => 0u8,
12+
};
13+
let _y: u32 = x; //~ ERROR mismatched types
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
error: expected identifier, found keyword `if`
2+
--> $DIR/recover-parens-around-match-arm-head.rs:4:12
3+
|
4+
LL | (0 if true) => {
5+
| ^^ expected identifier, found keyword
6+
7+
error: expected one of `)`, `,`, `...`, `..=`, `..`, or `|`, found keyword `if`
8+
--> $DIR/recover-parens-around-match-arm-head.rs:4:12
9+
|
10+
LL | (0 if true) => {
11+
| -^^ expected one of `)`, `,`, `...`, `..=`, `..`, or `|`
12+
| |
13+
| help: missing `,`
14+
15+
error: expected one of `)`, `,`, `@`, or `|`, found keyword `true`
16+
--> $DIR/recover-parens-around-match-arm-head.rs:4:15
17+
|
18+
LL | (0 if true) => {
19+
| -^^^^ expected one of `)`, `,`, `@`, or `|`
20+
| |
21+
| help: missing `,`
22+
23+
error[E0308]: mismatched types
24+
--> $DIR/recover-parens-around-match-arm-head.rs:4:9
25+
|
26+
LL | let x = match val {
27+
| --- this expression has type `{integer}`
28+
LL | (0 if true) => {
29+
| ^^^^^^^^^^^ expected integer, found `(_, _, _)`
30+
|
31+
= note: expected type `{integer}`
32+
found tuple `(_, _, _)`
33+
34+
error[E0308]: mismatched types
35+
--> $DIR/recover-parens-around-match-arm-head.rs:13:19
36+
|
37+
LL | let _y: u32 = x;
38+
| --- ^ expected `u32`, found `u8`
39+
| |
40+
| expected due to this
41+
|
42+
help: you can convert a `u8` to a `u32`
43+
|
44+
LL | let _y: u32 = x.into();
45+
| +++++++
46+
47+
error: aborting due to 5 previous errors
48+
49+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)