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
}, 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`

View file

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