Recover more expressions in patterns
This commit is contained in:
parent
7fc70f870a
commit
c2047219b5
20 changed files with 631 additions and 280 deletions
|
@ -1,5 +1,6 @@
|
|||
//@ error-pattern: expected
|
||||
|
||||
fn main() {
|
||||
let x.y::<isize>.z foo;
|
||||
//~^ error: field expressions cannot have generic arguments
|
||||
//~| error: expected a pattern, found an expression
|
||||
//~| error: expected one of `(`, `.`, `::`, `:`, `;`, `=`, `?`, `|`, or an operator, found `foo`
|
||||
}
|
||||
|
|
|
@ -1,8 +1,20 @@
|
|||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
|
||||
--> $DIR/bad-name.rs:4:8
|
||||
error: field expressions cannot have generic arguments
|
||||
--> $DIR/bad-name.rs:2:12
|
||||
|
|
||||
LL | let x.y::<isize>.z foo;
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|`
|
||||
| ^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/bad-name.rs:2:7
|
||||
|
|
||||
LL | let x.y::<isize>.z foo;
|
||||
| ^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected one of `(`, `.`, `::`, `:`, `;`, `=`, `?`, `|`, or an operator, found `foo`
|
||||
--> $DIR/bad-name.rs:2:22
|
||||
|
|
||||
LL | let x.y::<isize>.z foo;
|
||||
| ^^^ expected one of 9 possible tokens
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
fn main() {
|
||||
match u8::MAX {
|
||||
u8::MAX.abs() => (),
|
||||
//~^ error: expected a pattern, found a method call
|
||||
x.sqrt() @ .. => (),
|
||||
//~^ error: expected a pattern, found a method call
|
||||
//~| error: left-hand side of `@` must be a binding
|
||||
z @ w @ v.u() => (),
|
||||
//~^ error: expected a pattern, found a method call
|
||||
y.ilog(3) => (),
|
||||
//~^ error: expected a pattern, found a method call
|
||||
n + 1 => (),
|
||||
//~^ error: expected a pattern, found an expression
|
||||
("".f() + 14 * 8) => (),
|
||||
//~^ error: expected a pattern, found an expression
|
||||
0 | ((1) | 2) | 3 => (),
|
||||
f?() => (),
|
||||
//~^ error: expected a pattern, found an expression
|
||||
(_ + 1) => (),
|
||||
//~^ error: expected one of `)`, `,`, or `|`, found `+`
|
||||
}
|
||||
|
||||
let 1 + 1 = 2;
|
||||
//~^ error: expected a pattern, found an expression
|
||||
|
||||
let b = matches!(x, (x * x | x.f()) | x[0]);
|
||||
//~^ error: expected one of `)`, `,`, `@`, or `|`, found `*`
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
error: expected a pattern, found a method call
|
||||
--> $DIR/pat-recover-exprs.rs:3:9
|
||||
|
|
||||
LL | u8::MAX.abs() => (),
|
||||
| ^^^^^^^^^^^^^ method calls are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found a method call
|
||||
--> $DIR/pat-recover-exprs.rs:5:9
|
||||
|
|
||||
LL | x.sqrt() @ .. => (),
|
||||
| ^^^^^^^^ method calls are not allowed in patterns
|
||||
|
||||
error: left-hand side of `@` must be a binding
|
||||
--> $DIR/pat-recover-exprs.rs:5:9
|
||||
|
|
||||
LL | x.sqrt() @ .. => (),
|
||||
| --------^^^--
|
||||
| | |
|
||||
| | also a pattern
|
||||
| interpreted as a pattern, not a binding
|
||||
|
|
||||
= note: bindings are `x`, `mut x`, `ref x`, and `ref mut x`
|
||||
|
||||
error: expected a pattern, found a method call
|
||||
--> $DIR/pat-recover-exprs.rs:8:17
|
||||
|
|
||||
LL | z @ w @ v.u() => (),
|
||||
| ^^^^^ method calls are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found a method call
|
||||
--> $DIR/pat-recover-exprs.rs:10:9
|
||||
|
|
||||
LL | y.ilog(3) => (),
|
||||
| ^^^^^^^^^ method calls are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/pat-recover-exprs.rs:12:9
|
||||
|
|
||||
LL | n + 1 => (),
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/pat-recover-exprs.rs:14:10
|
||||
|
|
||||
LL | ("".f() + 14 * 8) => (),
|
||||
| ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/pat-recover-exprs.rs:17:9
|
||||
|
|
||||
LL | f?() => (),
|
||||
| ^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected one of `)`, `,`, or `|`, found `+`
|
||||
--> $DIR/pat-recover-exprs.rs:19:12
|
||||
|
|
||||
LL | (_ + 1) => (),
|
||||
| ^ expected one of `)`, `,`, or `|`
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/pat-recover-exprs.rs:23:9
|
||||
|
|
||||
LL | let 1 + 1 = 2;
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected one of `)`, `,`, `@`, or `|`, found `*`
|
||||
--> $DIR/pat-recover-exprs.rs:26:28
|
||||
|
|
||||
LL | let b = matches!(x, (x * x | x.f()) | x[0]);
|
||||
| ^ expected one of `)`, `,`, `@`, or `|`
|
||||
--> $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
||||
|
|
||||
= note: while parsing argument for this `pat` macro fragment
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
struct Foo(String);
|
||||
struct Bar { baz: String }
|
||||
|
||||
fn foo(foo: Foo) -> bool {
|
||||
match foo {
|
||||
Foo("hi".to_owned()) => true,
|
||||
//~^ error: expected a pattern, found a method call
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
fn bar(bar: Bar) -> bool {
|
||||
match bar {
|
||||
Bar { baz: "hi".to_owned() } => true,
|
||||
//~^ error: expected a pattern, found a method call
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
fn baz() { // issue #90121
|
||||
let foo = vec!["foo".to_string()];
|
||||
|
||||
match foo.as_slice() {
|
||||
&["foo".to_string()] => {}
|
||||
//~^ error: expected a pattern, found a method call
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let (-1.some(4)) = (0, Some(4)) {}
|
||||
//~^ error: expected a pattern, found a method call
|
||||
|
||||
if let (-1.Some(4)) = (0, Some(4)) {}
|
||||
//~^ error: expected one of `)`, `,`, `...`, `..=`, `..`, or `|`, found `.`
|
||||
//~| help: missing `,`
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
error: expected a pattern, found a method call
|
||||
--> $DIR/pat-recover-methodcalls.rs:6:13
|
||||
|
|
||||
LL | Foo("hi".to_owned()) => true,
|
||||
| ^^^^^^^^^^^^^^^ method calls are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found a method call
|
||||
--> $DIR/pat-recover-methodcalls.rs:14:20
|
||||
|
|
||||
LL | Bar { baz: "hi".to_owned() } => true,
|
||||
| ^^^^^^^^^^^^^^^ method calls are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found a method call
|
||||
--> $DIR/pat-recover-methodcalls.rs:24:11
|
||||
|
|
||||
LL | &["foo".to_string()] => {}
|
||||
| ^^^^^^^^^^^^^^^^^ method calls are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found a method call
|
||||
--> $DIR/pat-recover-methodcalls.rs:31:13
|
||||
|
|
||||
LL | if let (-1.some(4)) = (0, Some(4)) {}
|
||||
| ^^^^^^^^^^ method calls are not allowed in patterns
|
||||
|
||||
error: expected one of `)`, `,`, `...`, `..=`, `..`, or `|`, found `.`
|
||||
--> $DIR/pat-recover-methodcalls.rs:34:15
|
||||
|
|
||||
LL | if let (-1.Some(4)) = (0, Some(4)) {}
|
||||
| ^
|
||||
| |
|
||||
| expected one of `)`, `,`, `...`, `..=`, `..`, or `|`
|
||||
| help: missing `,`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
98
tests/ui/parser/recover/recover-pat-exprs.rs
Normal file
98
tests/ui/parser/recover/recover-pat-exprs.rs
Normal file
|
@ -0,0 +1,98 @@
|
|||
// FieldExpression, TupleIndexingExpression
|
||||
fn field_access() {
|
||||
match 0 {
|
||||
x => (),
|
||||
x.y => (), //~ error: expected a pattern, found an expression
|
||||
x.0 => (), //~ error: expected a pattern, found an expression
|
||||
x._0 => (), //~ error: expected a pattern, found an expression
|
||||
x.0.1 => (), //~ error: expected a pattern, found an expression
|
||||
x.4.y.17.__z => (), //~ error: expected a pattern, found an expression
|
||||
}
|
||||
|
||||
{ let x.0e0; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
|
||||
{ let x.-0.0; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
|
||||
{ let x.-0; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
|
||||
|
||||
{ let x.0u32; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
|
||||
{ let x.0.0_f64; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
|
||||
}
|
||||
|
||||
// IndexExpression, ArrayExpression
|
||||
fn array_indexing() {
|
||||
match 0 {
|
||||
x[0] => (), //~ error: expected a pattern, found an expression
|
||||
x[..] => (), //~ error: expected a pattern, found an expression
|
||||
}
|
||||
|
||||
{ let x[0, 1, 2]; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
|
||||
{ let x[0; 20]; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
|
||||
{ let x[]; } //~ error: expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
|
||||
{ let (x[]); } //~ error: expected one of `)`, `,`, `@`, or `|`, found `[`
|
||||
//~^ missing `,`
|
||||
}
|
||||
|
||||
// MethodCallExpression, CallExpression, ErrorPropagationExpression
|
||||
fn method_call() {
|
||||
match 0 {
|
||||
x.f() => (), //~ error: expected a pattern, found an expression
|
||||
x._f() => (), //~ error: expected a pattern, found an expression
|
||||
x? => (), //~ error: expected a pattern, found an expression
|
||||
().f() => (), //~ error: expected a pattern, found an expression
|
||||
(0, x)?.f() => (), //~ error: expected a pattern, found an expression
|
||||
x.f().g() => (), //~ error: expected a pattern, found an expression
|
||||
0.f()?.g()?? => (), //~ error: expected a pattern, found an expression
|
||||
}
|
||||
}
|
||||
|
||||
// TypeCastExpression
|
||||
fn type_cast() {
|
||||
match 0 {
|
||||
x as usize => (), //~ error: expected a pattern, found an expression
|
||||
0 as usize => (), //~ error: expected a pattern, found an expression
|
||||
x.f().0.4 as f32 => (), //~ error: expected a pattern, found an expression
|
||||
}
|
||||
}
|
||||
|
||||
// ArithmeticOrLogicalExpression
|
||||
fn operator() {
|
||||
match 0 {
|
||||
1 + 1 => (), //~ error: expected a pattern, found an expression
|
||||
(1 + 2) * 3 => (),
|
||||
//~^ error: expected a pattern, found an expression
|
||||
//~| error: expected a pattern, found an expression
|
||||
}
|
||||
}
|
||||
|
||||
const _: u32 = match 12 {
|
||||
1 + 2 * PI.cos() => 2, //~ error: expected a pattern, found an expression
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
match u8::MAX {
|
||||
u8::MAX.abs() => (),
|
||||
//~^ error: expected a pattern, found an expression
|
||||
x.sqrt() @ .. => (),
|
||||
//~^ error: expected a pattern, found an expression
|
||||
//~| error: left-hand side of `@` must be a binding
|
||||
z @ w @ v.u() => (),
|
||||
//~^ error: expected a pattern, found an expression
|
||||
y.ilog(3) => (),
|
||||
//~^ error: expected a pattern, found an expression
|
||||
n + 1 => (),
|
||||
//~^ error: expected a pattern, found an expression
|
||||
("".f() + 14 * 8) => (),
|
||||
//~^ error: expected a pattern, found an expression
|
||||
0 | ((1) | 2) | 3 => (),
|
||||
f?() => (),
|
||||
//~^ error: expected a pattern, found an expression
|
||||
(_ + 1) => (),
|
||||
//~^ error: expected one of `)`, `,`, or `|`, found `+`
|
||||
}
|
||||
|
||||
let 1 + 1 = 2;
|
||||
//~^ error: expected a pattern, found an expression
|
||||
|
||||
let b = matches!(x, (x * x | x.f()) | x[0]);
|
||||
//~^ error: expected one of `)`, `,`, `@`, or `|`, found `*`
|
||||
}
|
259
tests/ui/parser/recover/recover-pat-exprs.stderr
Normal file
259
tests/ui/parser/recover/recover-pat-exprs.stderr
Normal file
|
@ -0,0 +1,259 @@
|
|||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:5:9
|
||||
|
|
||||
LL | x.y => (),
|
||||
| ^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:6:9
|
||||
|
|
||||
LL | x.0 => (),
|
||||
| ^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:7:9
|
||||
|
|
||||
LL | x._0 => (),
|
||||
| ^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:8:9
|
||||
|
|
||||
LL | x.0.1 => (),
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:9:9
|
||||
|
|
||||
LL | x.4.y.17.__z => (),
|
||||
| ^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
|
||||
--> $DIR/recover-pat-exprs.rs:12:12
|
||||
|
|
||||
LL | { let x.0e0; }
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|`
|
||||
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
|
||||
--> $DIR/recover-pat-exprs.rs:13:12
|
||||
|
|
||||
LL | { let x.-0.0; }
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|`
|
||||
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
|
||||
--> $DIR/recover-pat-exprs.rs:14:12
|
||||
|
|
||||
LL | { let x.-0; }
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|`
|
||||
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
|
||||
--> $DIR/recover-pat-exprs.rs:16:12
|
||||
|
|
||||
LL | { let x.0u32; }
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|`
|
||||
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
|
||||
--> $DIR/recover-pat-exprs.rs:17:12
|
||||
|
|
||||
LL | { let x.0.0_f64; }
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|`
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:23:9
|
||||
|
|
||||
LL | x[0] => (),
|
||||
| ^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:24:9
|
||||
|
|
||||
LL | x[..] => (),
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
|
||||
--> $DIR/recover-pat-exprs.rs:27:12
|
||||
|
|
||||
LL | { let x[0, 1, 2]; }
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|`
|
||||
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
|
||||
--> $DIR/recover-pat-exprs.rs:28:12
|
||||
|
|
||||
LL | { let x[0; 20]; }
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|`
|
||||
|
||||
error: expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
|
||||
--> $DIR/recover-pat-exprs.rs:29:12
|
||||
|
|
||||
LL | { let x[]; }
|
||||
| ^ expected one of `:`, `;`, `=`, `@`, or `|`
|
||||
|
||||
error: expected one of `)`, `,`, `@`, or `|`, found `[`
|
||||
--> $DIR/recover-pat-exprs.rs:30:13
|
||||
|
|
||||
LL | { let (x[]); }
|
||||
| ^
|
||||
| |
|
||||
| expected one of `)`, `,`, `@`, or `|`
|
||||
| help: missing `,`
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:37:9
|
||||
|
|
||||
LL | x.f() => (),
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:38:9
|
||||
|
|
||||
LL | x._f() => (),
|
||||
| ^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:39:9
|
||||
|
|
||||
LL | x? => (),
|
||||
| ^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:40:9
|
||||
|
|
||||
LL | ().f() => (),
|
||||
| ^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:41:9
|
||||
|
|
||||
LL | (0, x)?.f() => (),
|
||||
| ^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:42:9
|
||||
|
|
||||
LL | x.f().g() => (),
|
||||
| ^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:43:9
|
||||
|
|
||||
LL | 0.f()?.g()?? => (),
|
||||
| ^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:50:9
|
||||
|
|
||||
LL | x as usize => (),
|
||||
| ^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:51:9
|
||||
|
|
||||
LL | 0 as usize => (),
|
||||
| ^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:52:9
|
||||
|
|
||||
LL | x.f().0.4 as f32 => (),
|
||||
| ^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:59:9
|
||||
|
|
||||
LL | 1 + 1 => (),
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:60:10
|
||||
|
|
||||
LL | (1 + 2) * 3 => (),
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:60:9
|
||||
|
|
||||
LL | (1 + 2) * 3 => (),
|
||||
| ^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:67:5
|
||||
|
|
||||
LL | 1 + 2 * PI.cos() => 2,
|
||||
| ^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:73:9
|
||||
|
|
||||
LL | u8::MAX.abs() => (),
|
||||
| ^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:75:9
|
||||
|
|
||||
LL | x.sqrt() @ .. => (),
|
||||
| ^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: left-hand side of `@` must be a binding
|
||||
--> $DIR/recover-pat-exprs.rs:75:9
|
||||
|
|
||||
LL | x.sqrt() @ .. => (),
|
||||
| --------^^^--
|
||||
| | |
|
||||
| | also a pattern
|
||||
| interpreted as a pattern, not a binding
|
||||
|
|
||||
= note: bindings are `x`, `mut x`, `ref x`, and `ref mut x`
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:78:17
|
||||
|
|
||||
LL | z @ w @ v.u() => (),
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:80:9
|
||||
|
|
||||
LL | y.ilog(3) => (),
|
||||
| ^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:82:9
|
||||
|
|
||||
LL | n + 1 => (),
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:84:10
|
||||
|
|
||||
LL | ("".f() + 14 * 8) => (),
|
||||
| ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:87:9
|
||||
|
|
||||
LL | f?() => (),
|
||||
| ^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected one of `)`, `,`, or `|`, found `+`
|
||||
--> $DIR/recover-pat-exprs.rs:89:12
|
||||
|
|
||||
LL | (_ + 1) => (),
|
||||
| ^ expected one of `)`, `,`, or `|`
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-exprs.rs:93:9
|
||||
|
|
||||
LL | let 1 + 1 = 2;
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected one of `)`, `,`, `@`, or `|`, found `*`
|
||||
--> $DIR/recover-pat-exprs.rs:96:28
|
||||
|
|
||||
LL | let b = matches!(x, (x * x | x.f()) | x[0]);
|
||||
| ^ expected one of `)`, `,`, `@`, or `|`
|
||||
--> $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
||||
|
|
||||
= note: while parsing argument for this `pat` macro fragment
|
||||
|
||||
error: aborting due to 41 previous errors
|
||||
|
46
tests/ui/parser/recover/recover-pat-issues.rs
Normal file
46
tests/ui/parser/recover/recover-pat-issues.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
struct Foo(String);
|
||||
struct Bar { baz: String }
|
||||
|
||||
fn foo(foo: Foo) -> bool {
|
||||
match foo {
|
||||
Foo("hi".to_owned()) => true,
|
||||
//~^ error: expected a pattern, found an expression
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
fn bar(bar: Bar) -> bool {
|
||||
match bar {
|
||||
Bar { baz: "hi".to_owned() } => true,
|
||||
//~^ error: expected a pattern, found an expression
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
/// Issue #90121
|
||||
fn baz() {
|
||||
let foo = vec!["foo".to_string()];
|
||||
|
||||
match foo.as_slice() {
|
||||
&["foo".to_string()] => {}
|
||||
//~^ error: expected a pattern, found an expression
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
||||
/// Issue #104996
|
||||
fn qux() {
|
||||
struct Magic(pub u16);
|
||||
const MAGIC: Magic = Magic(42);
|
||||
|
||||
if let Some(MAGIC.0 as usize) = None::<usize> {}
|
||||
//~^ error: expected a pattern, found an expression
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let (-1.some(4)) = (0, Some(4)) {}
|
||||
//~^ error: expected a pattern, found an expression
|
||||
|
||||
if let (-1.Some(4)) = (0, Some(4)) {}
|
||||
//~^ error: expected a pattern, found an expression
|
||||
}
|
38
tests/ui/parser/recover/recover-pat-issues.stderr
Normal file
38
tests/ui/parser/recover/recover-pat-issues.stderr
Normal file
|
@ -0,0 +1,38 @@
|
|||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-issues.rs:6:13
|
||||
|
|
||||
LL | Foo("hi".to_owned()) => true,
|
||||
| ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-issues.rs:14:20
|
||||
|
|
||||
LL | Bar { baz: "hi".to_owned() } => true,
|
||||
| ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-issues.rs:25:11
|
||||
|
|
||||
LL | &["foo".to_string()] => {}
|
||||
| ^^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-issues.rs:36:17
|
||||
|
|
||||
LL | if let Some(MAGIC.0 as usize) = None::<usize> {}
|
||||
| ^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-issues.rs:41:13
|
||||
|
|
||||
LL | if let (-1.some(4)) = (0, Some(4)) {}
|
||||
| ^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-issues.rs:44:13
|
||||
|
|
||||
LL | if let (-1.Some(4)) = (0, Some(4)) {}
|
||||
| ^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
20
tests/ui/parser/recover/recover-pat-lets.rs
Normal file
20
tests/ui/parser/recover/recover-pat-lets.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
fn main() {
|
||||
let x = Some(2);
|
||||
|
||||
let x.expect("foo");
|
||||
//~^ error: expected a pattern, found an expression
|
||||
|
||||
let x.unwrap(): u32;
|
||||
//~^ error: expected a pattern, found an expression
|
||||
|
||||
let x[0] = 1;
|
||||
//~^ error: expected a pattern, found an expression
|
||||
|
||||
let Some(1 + 1) = x else { //~ error: expected a pattern, found an expression
|
||||
return;
|
||||
};
|
||||
|
||||
if let Some(1 + 1) = x { //~ error: expected a pattern, found an expression
|
||||
return;
|
||||
}
|
||||
}
|
32
tests/ui/parser/recover/recover-pat-lets.stderr
Normal file
32
tests/ui/parser/recover/recover-pat-lets.stderr
Normal file
|
@ -0,0 +1,32 @@
|
|||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-lets.rs:4:9
|
||||
|
|
||||
LL | let x.expect("foo");
|
||||
| ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-lets.rs:7:9
|
||||
|
|
||||
LL | let x.unwrap(): u32;
|
||||
| ^^^^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-lets.rs:10:9
|
||||
|
|
||||
LL | let x[0] = 1;
|
||||
| ^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-lets.rs:13:14
|
||||
|
|
||||
LL | let Some(1 + 1) = x else {
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern, found an expression
|
||||
--> $DIR/recover-pat-lets.rs:17:17
|
||||
|
|
||||
LL | if let Some(1 + 1) = x {
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
|
@ -22,8 +22,8 @@ fn main() {
|
|||
//~| warning: `...` range patterns are deprecated
|
||||
//~| warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
|
||||
0.x()..="y".z() => (),
|
||||
//~^ error: expected a pattern range bound, found a method call
|
||||
//~| error: expected a pattern range bound, found a method call
|
||||
//~^ error: expected a pattern range bound, found an expression
|
||||
//~| error: expected a pattern range bound, found an expression
|
||||
};
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error: range pattern bounds cannot have parentheses
|
||||
--> $DIR/pat-recover-ranges.rs:4:13
|
||||
--> $DIR/recover-pat-ranges.rs:4:13
|
||||
|
|
||||
LL | 0..=(1) => (),
|
||||
| ^ ^
|
||||
|
@ -11,7 +11,7 @@ LL + 0..=1 => (),
|
|||
|
|
||||
|
||||
error: range pattern bounds cannot have parentheses
|
||||
--> $DIR/pat-recover-ranges.rs:6:9
|
||||
--> $DIR/recover-pat-ranges.rs:6:9
|
||||
|
|
||||
LL | (-12)..=4 => (),
|
||||
| ^ ^
|
||||
|
@ -23,7 +23,7 @@ LL + -12..=4 => (),
|
|||
|
|
||||
|
||||
error: range pattern bounds cannot have parentheses
|
||||
--> $DIR/pat-recover-ranges.rs:8:9
|
||||
--> $DIR/recover-pat-ranges.rs:8:9
|
||||
|
|
||||
LL | (0)..=(-4) => (),
|
||||
| ^ ^
|
||||
|
@ -35,7 +35,7 @@ LL + 0..=(-4) => (),
|
|||
|
|
||||
|
||||
error: range pattern bounds cannot have parentheses
|
||||
--> $DIR/pat-recover-ranges.rs:8:15
|
||||
--> $DIR/recover-pat-ranges.rs:8:15
|
||||
|
|
||||
LL | (0)..=(-4) => (),
|
||||
| ^ ^
|
||||
|
@ -47,13 +47,13 @@ LL + (0)..=-4 => (),
|
|||
|
|
||||
|
||||
error: expected a pattern range bound, found an expression
|
||||
--> $DIR/pat-recover-ranges.rs:11:12
|
||||
--> $DIR/recover-pat-ranges.rs:11:12
|
||||
|
|
||||
LL | ..=1 + 2 => (),
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: range pattern bounds cannot have parentheses
|
||||
--> $DIR/pat-recover-ranges.rs:13:9
|
||||
--> $DIR/recover-pat-ranges.rs:13:9
|
||||
|
|
||||
LL | (4).. => (),
|
||||
| ^ ^
|
||||
|
@ -65,13 +65,13 @@ LL + 4.. => (),
|
|||
|
|
||||
|
||||
error: expected a pattern range bound, found an expression
|
||||
--> $DIR/pat-recover-ranges.rs:15:10
|
||||
--> $DIR/recover-pat-ranges.rs:15:10
|
||||
|
|
||||
LL | (-4 + 0).. => (),
|
||||
| ^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: range pattern bounds cannot have parentheses
|
||||
--> $DIR/pat-recover-ranges.rs:15:9
|
||||
--> $DIR/recover-pat-ranges.rs:15:9
|
||||
|
|
||||
LL | (-4 + 0).. => (),
|
||||
| ^ ^
|
||||
|
@ -83,13 +83,13 @@ LL + -4 + 0.. => (),
|
|||
|
|
||||
|
||||
error: expected a pattern range bound, found an expression
|
||||
--> $DIR/pat-recover-ranges.rs:18:10
|
||||
--> $DIR/recover-pat-ranges.rs:18:10
|
||||
|
|
||||
LL | (1 + 4)...1 * 2 => (),
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: range pattern bounds cannot have parentheses
|
||||
--> $DIR/pat-recover-ranges.rs:18:9
|
||||
--> $DIR/recover-pat-ranges.rs:18:9
|
||||
|
|
||||
LL | (1 + 4)...1 * 2 => (),
|
||||
| ^ ^
|
||||
|
@ -101,25 +101,25 @@ LL + 1 + 4...1 * 2 => (),
|
|||
|
|
||||
|
||||
error: expected a pattern range bound, found an expression
|
||||
--> $DIR/pat-recover-ranges.rs:18:19
|
||||
--> $DIR/recover-pat-ranges.rs:18:19
|
||||
|
|
||||
LL | (1 + 4)...1 * 2 => (),
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern range bound, found a method call
|
||||
--> $DIR/pat-recover-ranges.rs:24:9
|
||||
error: expected a pattern range bound, found an expression
|
||||
--> $DIR/recover-pat-ranges.rs:24:9
|
||||
|
|
||||
LL | 0.x()..="y".z() => (),
|
||||
| ^^^^^ method calls are not allowed in patterns
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: expected a pattern range bound, found a method call
|
||||
--> $DIR/pat-recover-ranges.rs:24:17
|
||||
error: expected a pattern range bound, found an expression
|
||||
--> $DIR/recover-pat-ranges.rs:24:17
|
||||
|
|
||||
LL | 0.x()..="y".z() => (),
|
||||
| ^^^^^^^ method calls are not allowed in patterns
|
||||
| ^^^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
warning: `...` range patterns are deprecated
|
||||
--> $DIR/pat-recover-ranges.rs:18:16
|
||||
--> $DIR/recover-pat-ranges.rs:18:16
|
||||
|
|
||||
LL | (1 + 4)...1 * 2 => (),
|
||||
| ^^^ help: use `..=` for an inclusive range
|
|
@ -1,35 +1,35 @@
|
|||
error: expected one of `=>`, `if`, or `|`, found `+`
|
||||
--> $DIR/pat-recover-wildcards.rs:5:11
|
||||
--> $DIR/recover-pat-wildcards.rs:5:11
|
||||
|
|
||||
LL | _ + 1 => ()
|
||||
| ^ expected one of `=>`, `if`, or `|`
|
||||
|
||||
error: expected one of `)`, `,`, or `|`, found `%`
|
||||
--> $DIR/pat-recover-wildcards.rs:11:12
|
||||
--> $DIR/recover-pat-wildcards.rs:11:12
|
||||
|
|
||||
LL | (_ % 4) => ()
|
||||
| ^ expected one of `)`, `,`, or `|`
|
||||
|
||||
error: expected one of `=>`, `if`, or `|`, found `.`
|
||||
--> $DIR/pat-recover-wildcards.rs:17:10
|
||||
--> $DIR/recover-pat-wildcards.rs:17:10
|
||||
|
|
||||
LL | _.x() => ()
|
||||
| ^ expected one of `=>`, `if`, or `|`
|
||||
|
||||
error: expected one of `=>`, `if`, or `|`, found `..=`
|
||||
--> $DIR/pat-recover-wildcards.rs:23:10
|
||||
--> $DIR/recover-pat-wildcards.rs:23:10
|
||||
|
|
||||
LL | _..=4 => ()
|
||||
| ^^^ expected one of `=>`, `if`, or `|`
|
||||
|
||||
error: expected one of `=>`, `if`, or `|`, found reserved identifier `_`
|
||||
--> $DIR/pat-recover-wildcards.rs:29:11
|
||||
--> $DIR/recover-pat-wildcards.rs:29:11
|
||||
|
|
||||
LL | .._ => ()
|
||||
| ^ expected one of `=>`, `if`, or `|`
|
||||
|
||||
error[E0586]: inclusive range with no end
|
||||
--> $DIR/pat-recover-wildcards.rs:35:10
|
||||
--> $DIR/recover-pat-wildcards.rs:35:10
|
||||
|
|
||||
LL | 0..._ => ()
|
||||
| ^^^
|
||||
|
@ -42,31 +42,31 @@ LL + 0.._ => ()
|
|||
|
|
||||
|
||||
error: expected one of `=>`, `if`, or `|`, found reserved identifier `_`
|
||||
--> $DIR/pat-recover-wildcards.rs:35:13
|
||||
--> $DIR/recover-pat-wildcards.rs:35:13
|
||||
|
|
||||
LL | 0..._ => ()
|
||||
| ^ expected one of `=>`, `if`, or `|`
|
||||
|
||||
error: expected one of `)`, `,`, or `|`, found `*`
|
||||
--> $DIR/pat-recover-wildcards.rs:43:12
|
||||
--> $DIR/recover-pat-wildcards.rs:43:12
|
||||
|
|
||||
LL | (_ * 0)..5 => ()
|
||||
| ^ expected one of `)`, `,`, or `|`
|
||||
|
||||
error: expected one of `=>`, `if`, or `|`, found `(`
|
||||
--> $DIR/pat-recover-wildcards.rs:49:11
|
||||
--> $DIR/recover-pat-wildcards.rs:49:11
|
||||
|
|
||||
LL | ..(_) => ()
|
||||
| ^ expected one of `=>`, `if`, or `|`
|
||||
|
||||
error: expected a pattern range bound, found an expression
|
||||
--> $DIR/pat-recover-wildcards.rs:55:14
|
||||
--> $DIR/recover-pat-wildcards.rs:55:14
|
||||
|
|
||||
LL | 4..=(2 + _) => ()
|
||||
| ^^^^^ arbitrary expressions are not allowed in patterns
|
||||
|
||||
error: range pattern bounds cannot have parentheses
|
||||
--> $DIR/pat-recover-wildcards.rs:55:13
|
||||
--> $DIR/recover-pat-wildcards.rs:55:13
|
||||
|
|
||||
LL | 4..=(2 + _) => ()
|
||||
| ^ ^
|
Loading…
Add table
Add a link
Reference in a new issue