Skip to content

Commit a77a8aa

Browse files
committed
syntax: add test for intersection pattern parser recovery
1 parent 29fb07d commit a77a8aa

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// This tests the parser recovery in `recover_intersection_pat`
2+
// and serves as a regression test for the diagnostics issue #65400.
3+
//
4+
// The general idea is that for `$pat_lhs @ $pat_rhs` where
5+
// `$pat_lhs` is not generated by `ref? mut? $ident` we want
6+
// to suggest either switching the order or note that intersection
7+
// patterns are not allowed.
8+
9+
fn main() {
10+
let s: Option<u8> = None;
11+
12+
match s {
13+
Some(x) @ y => {}
14+
//~^ ERROR pattern on wrong side of `@`
15+
//~| pattern on the left, should be to the right
16+
//~| binding on the right, should be to the left
17+
//~| HELP switch the order
18+
//~| SUGGESTION y@Some(x)
19+
_ => {}
20+
}
21+
22+
match s {
23+
Some(x) @ Some(y) => {}
24+
//~^ ERROR left-hand side of `@` must be a binding pattern
25+
//~| interpreted as a pattern, not a binding
26+
//~| also a pattern
27+
//~| NOTE bindings are `x`, `mut x`, `ref x`, and `ref mut x`
28+
_ => {}
29+
}
30+
31+
match 2 {
32+
1 ..= 5 @ e => {}
33+
//~^ ERROR pattern on wrong side of `@`
34+
//~| pattern on the left, should be to the right
35+
//~| binding on the right, should be to the left
36+
//~| HELP switch the order
37+
//~| SUGGESTION e@1 ..=5
38+
_ => {}
39+
}
40+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error: pattern on wrong side of `@`
2+
--> $DIR/intersection-patterns.rs:13:9
3+
|
4+
LL | Some(x) @ y => {}
5+
| -------^^^-
6+
| | |
7+
| | binding on the right, should be to the left
8+
| pattern on the left, should be to the right
9+
| help: switch the order: `y@Some(x)`
10+
11+
error: left-hand side of `@` must be a binding pattern
12+
--> $DIR/intersection-patterns.rs:23:9
13+
|
14+
LL | Some(x) @ Some(y) => {}
15+
| -------^^^-------
16+
| | |
17+
| | also a pattern
18+
| interpreted as a pattern, not a binding
19+
|
20+
= note: bindings are `x`, `mut x`, `ref x`, and `ref mut x`
21+
22+
error: pattern on wrong side of `@`
23+
--> $DIR/intersection-patterns.rs:32:9
24+
|
25+
LL | 1 ..= 5 @ e => {}
26+
| -------^^^-
27+
| | |
28+
| | binding on the right, should be to the left
29+
| pattern on the left, should be to the right
30+
| help: switch the order: `e@1 ..=5`
31+
32+
error: aborting due to 3 previous errors
33+

0 commit comments

Comments
 (0)