Always suggest as MachineApplicable in recover_intersection_pat

Signed-off-by: Yuki Okushi <jtitor@2k36.org>
This commit is contained in:
Yuki Okushi 2022-12-23 07:18:48 +09:00
parent cca80b9a81
commit 668d9fd7bc
No known key found for this signature in database
6 changed files with 81 additions and 35 deletions

View file

@ -0,0 +1,35 @@
// This tests the parser recovery in `recover_intersection_pat`
// and serves as a regression test for the diagnostics issue #65400.
//
// The general idea is that for `$pat_lhs @ $pat_rhs` where
// `$pat_lhs` is not generated by `ref? mut? $ident` we want
// to suggest either switching the order or note that intersection
// patterns are not allowed.
// run-rustfix
#![allow(unused_variables)]
fn main() {
let s: Option<u8> = None;
match s {
y @ Some(x) => {}
//~^ ERROR pattern on wrong side of `@`
//~| pattern on the left, should be on the right
//~| binding on the right, should be on the left
//~| HELP switch the order
//~| SUGGESTION y @ Some(x)
_ => {}
}
match 2 {
e @ 1..=5 => {}
//~^ ERROR pattern on wrong side of `@`
//~| pattern on the left, should be on the right
//~| binding on the right, should be on the left
//~| HELP switch the order
//~| SUGGESTION e @ 1..=5
_ => {}
}
}

View file

@ -6,6 +6,10 @@
// to suggest either switching the order or note that intersection
// patterns are not allowed.
// run-rustfix
#![allow(unused_variables)]
fn main() {
let s: Option<u8> = None;
@ -19,15 +23,6 @@ fn main() {
_ => {}
}
match s {
Some(x) @ Some(y) => {}
//~^ ERROR left-hand side of `@` must be a binding
//~| interpreted as a pattern, not a binding
//~| also a pattern
//~| NOTE bindings are `x`, `mut x`, `ref x`, and `ref mut x`
_ => {}
}
match 2 {
1 ..= 5 @ e => {}
//~^ ERROR pattern on wrong side of `@`

View file

@ -1,5 +1,5 @@
error: pattern on wrong side of `@`
--> $DIR/intersection-patterns.rs:13:9
--> $DIR/intersection-patterns-1.rs:17:9
|
LL | Some(x) @ y => {}
| -------^^^-
@ -8,19 +8,8 @@ LL | Some(x) @ y => {}
| pattern on the left, should be on the right
| help: switch the order: `y @ Some(x)`
error: left-hand side of `@` must be a binding
--> $DIR/intersection-patterns.rs:23:9
|
LL | Some(x) @ Some(y) => {}
| -------^^^-------
| | |
| | also a pattern
| interpreted as a pattern, not a binding
|
= note: bindings are `x`, `mut x`, `ref x`, and `ref mut x`
error: pattern on wrong side of `@`
--> $DIR/intersection-patterns.rs:32:9
--> $DIR/intersection-patterns-1.rs:27:9
|
LL | 1 ..= 5 @ e => {}
| -------^^^-
@ -29,5 +18,5 @@ LL | 1 ..= 5 @ e => {}
| pattern on the left, should be on the right
| help: switch the order: `e @ 1..=5`
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

View file

@ -0,0 +1,20 @@
// This tests the parser recovery in `recover_intersection_pat`
// and serves as a regression test for the diagnostics issue #65400.
//
// The general idea is that for `$pat_lhs @ $pat_rhs` where
// `$pat_lhs` is not generated by `ref? mut? $ident` we want
// to suggest either switching the order or note that intersection
// patterns are not allowed.
fn main() {
let s: Option<u8> = None;
match s {
Some(x) @ Some(y) => {}
//~^ ERROR left-hand side of `@` must be a binding
//~| interpreted as a pattern, not a binding
//~| also a pattern
//~| NOTE bindings are `x`, `mut x`, `ref x`, and `ref mut x`
_ => {}
}
}

View file

@ -0,0 +1,13 @@
error: left-hand side of `@` must be a binding
--> $DIR/intersection-patterns-2.rs:13:9
|
LL | Some(x) @ Some(y) => {}
| -------^^^-------
| | |
| | also a pattern
| interpreted as a pattern, not a binding
|
= note: bindings are `x`, `mut x`, `ref x`, and `ref mut x`
error: aborting due to previous error