On function and method calls in patterns, link to the book

```
error: expected a pattern, found an expression
 --> f889.rs:3:13
  |
3 |     let (x, y.drop()) = (1, 2); //~ ERROR
  |             ^^^^^^^^ not a pattern
  |
  = note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>

error[E0532]: expected a pattern, found a function call
 --> f889.rs:2:13
  |
2 |     let (x, drop(y)) = (1, 2); //~ ERROR
  |             ^^^^ not a tuple struct or tuple variant
  |
  = note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
```

Fix #97200.
This commit is contained in:
Esteban Küber 2024-10-06 01:44:59 +00:00
parent 14f303bc14
commit 7f5548fa8b
19 changed files with 156 additions and 64 deletions

View File

@ -812,7 +812,8 @@ parse_unexpected_expr_in_pat =
*[false] a pattern *[false] a pattern
}, found an expression }, found an expression
.label = arbitrary expressions are not allowed in patterns .label = not a pattern
.note = arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
parse_unexpected_expr_in_pat_const_sugg = consider extracting the expression into a `const` parse_unexpected_expr_in_pat_const_sugg = consider extracting the expression into a `const`

View File

@ -2608,6 +2608,7 @@ pub(crate) struct ExpectedCommaAfterPatternField {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(parse_unexpected_expr_in_pat)] #[diag(parse_unexpected_expr_in_pat)]
#[note]
pub(crate) struct UnexpectedExpressionInPattern { pub(crate) struct UnexpectedExpressionInPattern {
/// The unexpected expr's span. /// The unexpected expr's span.
#[primary_span] #[primary_span]

View File

@ -443,6 +443,7 @@ pub(crate) fn smart_resolve_report_errors(
self.suggest_bare_struct_literal(&mut err); self.suggest_bare_struct_literal(&mut err);
self.suggest_changing_type_to_const_param(&mut err, res, source, span); self.suggest_changing_type_to_const_param(&mut err, res, source, span);
self.explain_functions_in_pattern(&mut err, res, source);
if self.suggest_pattern_match_with_let(&mut err, source, span) { if self.suggest_pattern_match_with_let(&mut err, source, span) {
// Fallback label. // Fallback label.
@ -1166,6 +1167,18 @@ fn suggest_bare_struct_literal(&mut self, err: &mut Diag<'_>) {
} }
} }
fn explain_functions_in_pattern(
&mut self,
err: &mut Diag<'_>,
res: Option<Res>,
source: PathSource<'_>,
) {
let PathSource::TupleStruct(_, _) = source else { return };
let Some(Res::Def(DefKind::Fn, _)) = res else { return };
err.primary_message("expected a pattern, found a function call");
err.note("function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>");
}
fn suggest_changing_type_to_const_param( fn suggest_changing_type_to_const_param(
&mut self, &mut self,
err: &mut Diag<'_>, err: &mut Diag<'_>,

View File

@ -2,8 +2,9 @@ error: expected a pattern range bound, found an expression
--> $DIR/range_pat_interactions1.rs:17:16 --> $DIR/range_pat_interactions1.rs:17:16
| |
LL | 0..5+1 => errors_only.push(x), LL | 0..5+1 => errors_only.push(x),
| ^^^ arbitrary expressions are not allowed in patterns | ^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = 5+1; LL + const VAL: /* Type */ = 5+1;

View File

@ -14,8 +14,9 @@ error: expected a pattern range bound, found an expression
--> $DIR/range_pat_interactions2.rs:10:18 --> $DIR/range_pat_interactions2.rs:10:18
| |
LL | 0..=(5+1) => errors_only.push(x), LL | 0..=(5+1) => errors_only.push(x),
| ^^^ arbitrary expressions are not allowed in patterns | ^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = 5+1; LL + const VAL: /* Type */ = 5+1;

View File

@ -8,7 +8,9 @@ error: expected a pattern, found an expression
--> $DIR/bad-name.rs:2:7 --> $DIR/bad-name.rs:2:7
| |
LL | let x.y::<isize>.z foo; LL | let x.y::<isize>.z foo;
| ^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error: expected one of `(`, `.`, `::`, `:`, `;`, `=`, `?`, `|`, or an operator, found `foo` error: expected one of `(`, `.`, `::`, `:`, `;`, `=`, `?`, `|`, or an operator, found `foo`
--> $DIR/bad-name.rs:2:22 --> $DIR/bad-name.rs:2:22

View File

@ -2,7 +2,9 @@ error: expected a pattern, found an expression
--> $DIR/issue-24197.rs:2:9 --> $DIR/issue-24197.rs:2:9
| |
LL | let buf[0] = 0; LL | let buf[0] = 0;
| ^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -2,8 +2,9 @@ error: expected a pattern, found an expression
--> $DIR/issue-24375.rs:6:9 --> $DIR/issue-24375.rs:6:9
| |
LL | tmp[0] => {} LL | tmp[0] => {}
| ^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == tmp[0] => {} LL | val if val == tmp[0] => {}

View File

@ -2,7 +2,9 @@ error: expected a pattern, found an expression
--> $DIR/pat-lt-bracket-5.rs:2:9 --> $DIR/pat-lt-bracket-5.rs:2:9
| |
LL | let v[0] = v[1]; LL | let v[0] = v[1];
| ^^^^ arbitrary expressions are not allowed in patterns | ^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error[E0425]: cannot find value `v` in this scope error[E0425]: cannot find value `v` in this scope
--> $DIR/pat-lt-bracket-5.rs:2:16 --> $DIR/pat-lt-bracket-5.rs:2:16

View File

@ -2,7 +2,9 @@ error: expected a pattern, found an expression
--> $DIR/pat-lt-bracket-6.rs:5:14 --> $DIR/pat-lt-bracket-6.rs:5:14
| |
LL | let Test(&desc[..]) = x; LL | let Test(&desc[..]) = x;
| ^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/pat-lt-bracket-6.rs:10:30 --> $DIR/pat-lt-bracket-6.rs:10:30

View File

@ -2,13 +2,17 @@ error: expected a pattern range bound, found an expression
--> $DIR/pat-ranges-3.rs:4:16 --> $DIR/pat-ranges-3.rs:4:16
| |
LL | let 10 ..= 10 + 3 = 12; LL | let 10 ..= 10 + 3 = 12;
| ^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error: expected a pattern range bound, found an expression error: expected a pattern range bound, found an expression
--> $DIR/pat-ranges-3.rs:7:9 --> $DIR/pat-ranges-3.rs:7:9
| |
LL | let 10 - 3 ..= 10 = 8; LL | let 10 - 3 ..= 10 = 8;
| ^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View File

@ -2,8 +2,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:5:9 --> $DIR/recover-pat-exprs.rs:5:9
| |
LL | x.y => (), LL | x.y => (),
| ^^^ arbitrary expressions are not allowed in patterns | ^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x.y => (), LL | val if val == x.y => (),
@ -24,8 +25,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:6:9 --> $DIR/recover-pat-exprs.rs:6:9
| |
LL | x.0 => (), LL | x.0 => (),
| ^^^ arbitrary expressions are not allowed in patterns | ^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x.0 => (), LL | val if val == x.0 => (),
@ -47,8 +49,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:7:9 --> $DIR/recover-pat-exprs.rs:7:9
| |
LL | x._0 => (), LL | x._0 => (),
| ^^^^ arbitrary expressions are not allowed in patterns | ^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x._0 => (), LL | val if val == x._0 => (),
@ -71,8 +74,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:8:9 --> $DIR/recover-pat-exprs.rs:8:9
| |
LL | x.0.1 => (), LL | x.0.1 => (),
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x.0.1 => (), LL | val if val == x.0.1 => (),
@ -95,8 +99,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:9:9 --> $DIR/recover-pat-exprs.rs:9:9
| |
LL | x.4.y.17.__z => (), LL | x.4.y.17.__z => (),
| ^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x.4.y.17.__z => (), LL | val if val == x.4.y.17.__z => (),
@ -149,8 +154,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:23:9 --> $DIR/recover-pat-exprs.rs:23:9
| |
LL | x[0] => (), LL | x[0] => (),
| ^^^^ arbitrary expressions are not allowed in patterns | ^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x[0] => (), LL | val if val == x[0] => (),
@ -170,8 +176,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:24:9 --> $DIR/recover-pat-exprs.rs:24:9
| |
LL | x[..] => (), LL | x[..] => (),
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x[..] => (), LL | val if val == x[..] => (),
@ -219,8 +226,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:37:9 --> $DIR/recover-pat-exprs.rs:37:9
| |
LL | x.f() => (), LL | x.f() => (),
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x.f() => (), LL | val if val == x.f() => (),
@ -240,8 +248,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:38:9 --> $DIR/recover-pat-exprs.rs:38:9
| |
LL | x._f() => (), LL | x._f() => (),
| ^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x._f() => (), LL | val if val == x._f() => (),
@ -262,8 +271,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:39:9 --> $DIR/recover-pat-exprs.rs:39:9
| |
LL | x? => (), LL | x? => (),
| ^^ arbitrary expressions are not allowed in patterns | ^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x? => (), LL | val if val == x? => (),
@ -285,8 +295,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:40:9 --> $DIR/recover-pat-exprs.rs:40:9
| |
LL | ().f() => (), LL | ().f() => (),
| ^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == ().f() => (), LL | val if val == ().f() => (),
@ -309,8 +320,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:41:9 --> $DIR/recover-pat-exprs.rs:41:9
| |
LL | (0, x)?.f() => (), LL | (0, x)?.f() => (),
| ^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == (0, x)?.f() => (), LL | val if val == (0, x)?.f() => (),
@ -333,8 +345,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:42:9 --> $DIR/recover-pat-exprs.rs:42:9
| |
LL | x.f().g() => (), LL | x.f().g() => (),
| ^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x.f().g() => (), LL | val if val == x.f().g() => (),
@ -357,8 +370,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:43:9 --> $DIR/recover-pat-exprs.rs:43:9
| |
LL | 0.f()?.g()?? => (), LL | 0.f()?.g()?? => (),
| ^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == 0.f()?.g()?? => (), LL | val if val == 0.f()?.g()?? => (),
@ -381,8 +395,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:50:9 --> $DIR/recover-pat-exprs.rs:50:9
| |
LL | x as usize => (), LL | x as usize => (),
| ^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x as usize => (), LL | val if val == x as usize => (),
@ -402,8 +417,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:51:9 --> $DIR/recover-pat-exprs.rs:51:9
| |
LL | 0 as usize => (), LL | 0 as usize => (),
| ^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == 0 as usize => (), LL | val if val == 0 as usize => (),
@ -424,8 +440,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:52:9 --> $DIR/recover-pat-exprs.rs:52:9
| |
LL | x.f().0.4 as f32 => (), LL | x.f().0.4 as f32 => (),
| ^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == x.f().0.4 as f32 => (), LL | val if val == x.f().0.4 as f32 => (),
@ -447,8 +464,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:59:9 --> $DIR/recover-pat-exprs.rs:59:9
| |
LL | 1 + 1 => (), LL | 1 + 1 => (),
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == 1 + 1 => (), LL | val if val == 1 + 1 => (),
@ -468,8 +486,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:60:9 --> $DIR/recover-pat-exprs.rs:60:9
| |
LL | (1 + 2) * 3 => (), LL | (1 + 2) * 3 => (),
| ^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == (1 + 2) * 3 => (), LL | val if val == (1 + 2) * 3 => (),
@ -490,8 +509,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:63:9 --> $DIR/recover-pat-exprs.rs:63:9
| |
LL | x.0 > 2 => (), LL | x.0 > 2 => (),
| ^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == (x.0 > 2) => (), LL | val if val == (x.0 > 2) => (),
@ -514,8 +534,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:64:9 --> $DIR/recover-pat-exprs.rs:64:9
| |
LL | x.0 == 2 => (), LL | x.0 == 2 => (),
| ^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == (x.0 == 2) => (), LL | val if val == (x.0 == 2) => (),
@ -538,8 +559,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:69:13 --> $DIR/recover-pat-exprs.rs:69:13
| |
LL | (x, y.0 > 2) if x != 0 => (), LL | (x, y.0 > 2) if x != 0 => (),
| ^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to the match arm guard help: consider moving the expression to the match arm guard
| |
LL | (x, val) if x != 0 && val == (y.0 > 2) => (), LL | (x, val) if x != 0 && val == (y.0 > 2) => (),
@ -559,8 +581,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:70:13 --> $DIR/recover-pat-exprs.rs:70:13
| |
LL | (x, y.0 > 2) if x != 0 || x != 1 => (), LL | (x, y.0 > 2) if x != 0 || x != 1 => (),
| ^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to the match arm guard help: consider moving the expression to the match arm guard
| |
LL | (x, val) if (x != 0 || x != 1) && val == (y.0 > 2) => (), LL | (x, val) if (x != 0 || x != 1) && val == (y.0 > 2) => (),
@ -598,8 +621,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:81:9 --> $DIR/recover-pat-exprs.rs:81:9
| |
LL | u8::MAX.abs() => (), LL | u8::MAX.abs() => (),
| ^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == u8::MAX.abs() => (), LL | val if val == u8::MAX.abs() => (),
@ -619,8 +643,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:86:17 --> $DIR/recover-pat-exprs.rs:86:17
| |
LL | z @ w @ v.u() => (), LL | z @ w @ v.u() => (),
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | z @ w @ val if val == v.u() => (), LL | z @ w @ val if val == v.u() => (),
@ -643,8 +668,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:88:9 --> $DIR/recover-pat-exprs.rs:88:9
| |
LL | y.ilog(3) => (), LL | y.ilog(3) => (),
| ^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == y.ilog(3) => (), LL | val if val == y.ilog(3) => (),
@ -667,8 +693,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:90:9 --> $DIR/recover-pat-exprs.rs:90:9
| |
LL | n + 1 => (), LL | n + 1 => (),
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == n + 1 => (), LL | val if val == n + 1 => (),
@ -691,8 +718,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:92:10 --> $DIR/recover-pat-exprs.rs:92:10
| |
LL | ("".f() + 14 * 8) => (), LL | ("".f() + 14 * 8) => (),
| ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | (val) if val == "".f() + 14 * 8 => (), LL | (val) if val == "".f() + 14 * 8 => (),
@ -715,8 +743,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:95:9 --> $DIR/recover-pat-exprs.rs:95:9
| |
LL | f?() => (), LL | f?() => (),
| ^^^^ arbitrary expressions are not allowed in patterns | ^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | val if val == f?() => (), LL | val if val == f?() => (),
@ -739,7 +768,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:101:9 --> $DIR/recover-pat-exprs.rs:101:9
| |
LL | let 1 + 1 = 2; LL | let 1 + 1 = 2;
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error: expected one of `)`, `,`, `@`, or `|`, found `*` error: expected one of `)`, `,`, `@`, or `|`, found `*`
--> $DIR/recover-pat-exprs.rs:104:28 --> $DIR/recover-pat-exprs.rs:104:28
@ -754,19 +785,25 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:60:10 --> $DIR/recover-pat-exprs.rs:60:10
| |
LL | (1 + 2) * 3 => (), LL | (1 + 2) * 3 => (),
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error: expected a pattern, found an expression error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:75:5 --> $DIR/recover-pat-exprs.rs:75:5
| |
LL | 1 + 2 * PI.cos() => 2, LL | 1 + 2 * PI.cos() => 2,
| ^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error: expected a pattern, found an expression error: expected a pattern, found an expression
--> $DIR/recover-pat-exprs.rs:83:9 --> $DIR/recover-pat-exprs.rs:83:9
| |
LL | x.sqrt() @ .. => (), LL | x.sqrt() @ .. => (),
| ^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error: aborting due to 45 previous errors error: aborting due to 45 previous errors

View File

@ -2,8 +2,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-issues.rs:6:13 --> $DIR/recover-pat-issues.rs:6:13
| |
LL | Foo("hi".to_owned()) => true, LL | Foo("hi".to_owned()) => true,
| ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | Foo(val) if val == "hi".to_owned() => true, LL | Foo(val) if val == "hi".to_owned() => true,
@ -23,8 +24,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-issues.rs:14:20 --> $DIR/recover-pat-issues.rs:14:20
| |
LL | Bar { baz: "hi".to_owned() } => true, LL | Bar { baz: "hi".to_owned() } => true,
| ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | Bar { baz } if baz == "hi".to_owned() => true, LL | Bar { baz } if baz == "hi".to_owned() => true,
@ -44,8 +46,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-issues.rs:25:11 --> $DIR/recover-pat-issues.rs:25:11
| |
LL | &["foo".to_string()] => {} LL | &["foo".to_string()] => {}
| ^^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider moving the expression to a match arm guard help: consider moving the expression to a match arm guard
| |
LL | &[val] if val == "foo".to_string() => {} LL | &[val] if val == "foo".to_string() => {}
@ -65,8 +68,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-issues.rs:36:17 --> $DIR/recover-pat-issues.rs:36:17
| |
LL | if let Some(MAGIC.0 as usize) = None::<usize> {} LL | if let Some(MAGIC.0 as usize) = None::<usize> {}
| ^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = MAGIC.0 as usize; LL + const VAL: /* Type */ = MAGIC.0 as usize;
@ -81,8 +85,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-issues.rs:41:13 --> $DIR/recover-pat-issues.rs:41:13
| |
LL | if let (-1.some(4)) = (0, Some(4)) {} LL | if let (-1.some(4)) = (0, Some(4)) {}
| ^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = -1.some(4); LL + const VAL: /* Type */ = -1.some(4);
@ -97,8 +102,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-issues.rs:44:13 --> $DIR/recover-pat-issues.rs:44:13
| |
LL | if let (-1.Some(4)) = (0, Some(4)) {} LL | if let (-1.Some(4)) = (0, Some(4)) {}
| ^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = -1.Some(4); LL + const VAL: /* Type */ = -1.Some(4);

View File

@ -2,26 +2,33 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-lets.rs:4:9 --> $DIR/recover-pat-lets.rs:4:9
| |
LL | let x.expect("foo"); LL | let x.expect("foo");
| ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error: expected a pattern, found an expression error: expected a pattern, found an expression
--> $DIR/recover-pat-lets.rs:7:9 --> $DIR/recover-pat-lets.rs:7:9
| |
LL | let x.unwrap(): u32; LL | let x.unwrap(): u32;
| ^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error: expected a pattern, found an expression error: expected a pattern, found an expression
--> $DIR/recover-pat-lets.rs:10:9 --> $DIR/recover-pat-lets.rs:10:9
| |
LL | let x[0] = 1; LL | let x[0] = 1;
| ^^^^ arbitrary expressions are not allowed in patterns | ^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error: expected a pattern, found an expression error: expected a pattern, found an expression
--> $DIR/recover-pat-lets.rs:13:14 --> $DIR/recover-pat-lets.rs:13:14
| |
LL | let Some(1 + 1) = x else { LL | let Some(1 + 1) = x else {
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = 1 + 1; LL + const VAL: /* Type */ = 1 + 1;
@ -36,8 +43,9 @@ error: expected a pattern, found an expression
--> $DIR/recover-pat-lets.rs:17:17 --> $DIR/recover-pat-lets.rs:17:17
| |
LL | if let Some(1 + 1) = x { LL | if let Some(1 + 1) = x {
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = 1 + 1; LL + const VAL: /* Type */ = 1 + 1;

View File

@ -86,8 +86,9 @@ error: expected a pattern range bound, found an expression
--> $DIR/recover-pat-ranges.rs:11:12 --> $DIR/recover-pat-ranges.rs:11:12
| |
LL | ..=1 + 2 => (), LL | ..=1 + 2 => (),
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = 1 + 2; LL + const VAL: /* Type */ = 1 + 2;
@ -106,8 +107,9 @@ error: expected a pattern range bound, found an expression
--> $DIR/recover-pat-ranges.rs:15:10 --> $DIR/recover-pat-ranges.rs:15:10
| |
LL | (-4 + 0).. => (), LL | (-4 + 0).. => (),
| ^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = -4 + 0; LL + const VAL: /* Type */ = -4 + 0;
@ -126,8 +128,9 @@ error: expected a pattern range bound, found an expression
--> $DIR/recover-pat-ranges.rs:18:10 --> $DIR/recover-pat-ranges.rs:18:10
| |
LL | (1 + 4)...1 * 2 => (), LL | (1 + 4)...1 * 2 => (),
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = 1 + 4; LL + const VAL: /* Type */ = 1 + 4;
@ -146,8 +149,9 @@ error: expected a pattern range bound, found an expression
--> $DIR/recover-pat-ranges.rs:18:19 --> $DIR/recover-pat-ranges.rs:18:19
| |
LL | (1 + 4)...1 * 2 => (), LL | (1 + 4)...1 * 2 => (),
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = 1 * 2; LL + const VAL: /* Type */ = 1 * 2;
@ -166,8 +170,9 @@ error: expected a pattern range bound, found an expression
--> $DIR/recover-pat-ranges.rs:24:9 --> $DIR/recover-pat-ranges.rs:24:9
| |
LL | 0.x()..="y".z() => (), LL | 0.x()..="y".z() => (),
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = 0.x(); LL + const VAL: /* Type */ = 0.x();
@ -186,8 +191,9 @@ error: expected a pattern range bound, found an expression
--> $DIR/recover-pat-ranges.rs:24:17 --> $DIR/recover-pat-ranges.rs:24:17
| |
LL | 0.x()..="y".z() => (), LL | 0.x()..="y".z() => (),
| ^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = "y".z(); LL + const VAL: /* Type */ = "y".z();

View File

@ -75,8 +75,9 @@ error: expected a pattern range bound, found an expression
--> $DIR/recover-pat-wildcards.rs:55:14 --> $DIR/recover-pat-wildcards.rs:55:14
| |
LL | 4..=(2 + _) => () LL | 4..=(2 + _) => ()
| ^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^ not a pattern
| |
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
help: consider extracting the expression into a `const` help: consider extracting the expression into a `const`
| |
LL + const VAL: /* Type */ = 2 + _; LL + const VAL: /* Type */ = 2 + _;

View File

@ -3,7 +3,7 @@ fn foo(_: usize) -> Foo { Foo(false) }
fn main() { fn main() {
match Foo(true) { match Foo(true) {
foo(x) //~ ERROR expected tuple struct or tuple variant, found function `foo` foo(x) //~ ERROR expected a pattern, found a function call
=> () => ()
} }
} }

View File

@ -1,4 +1,4 @@
error[E0532]: expected tuple struct or tuple variant, found function `foo` error[E0532]: expected a pattern, found a function call
--> $DIR/issue-10200.rs:6:9 --> $DIR/issue-10200.rs:6:9
| |
LL | struct Foo(bool); LL | struct Foo(bool);
@ -6,6 +6,8 @@ LL | struct Foo(bool);
... ...
LL | foo(x) LL | foo(x)
| ^^^ help: a tuple struct with a similar name exists (notice the capitalization): `Foo` | ^^^ help: a tuple struct with a similar name exists (notice the capitalization): `Foo`
|
= note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -2,7 +2,9 @@ error: expected a pattern, found an expression
--> $DIR/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs:2:31 --> $DIR/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs:2:31
| |
LL | let str::<{fn str() { let str::T>>::as_bytes; }}, T>::as_bytes; LL | let str::<{fn str() { let str::T>>::as_bytes; }}, T>::as_bytes;
| ^^^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | ^^^^^^^^^^^^^^^^^^ not a pattern
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
error[E0412]: cannot find type `T` in this scope error[E0412]: cannot find type `T` in this scope
--> $DIR/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs:2:55 --> $DIR/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs:2:55