]> git.lizzy.rs Git - rust.git/blob - src/test/ui/parser/intersection-patterns.rs
Merge commit '40dd3e2b7089b5e96714e064b731f6dbf17c61a9' into sync_cg_clif-2021-05-27
[rust.git] / src / test / ui / parser / intersection-patterns.rs
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 on the right
16         //~| binding on the right, should be on 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
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 on the right
35         //~| binding on the right, should be on the left
36         //~| HELP switch the order
37         //~| SUGGESTION e @ 1 ..=5
38         _ => {}
39     }
40 }