rust/tests/ui/parser/recover/recover-pat-issues.stderr
Esteban Küber 7f5548fa8b 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.
2024-10-06 01:44:59 +00:00

120 lines
4.5 KiB
Plaintext

error: expected a pattern, found an expression
--> $DIR/recover-pat-issues.rs:6:13
|
LL | Foo("hi".to_owned()) => true,
| ^^^^^^^^^^^^^^^ 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
|
LL | Foo(val) if val == "hi".to_owned() => true,
| ~~~ +++++++++++++++++++++++++
help: consider extracting the expression into a `const`
|
LL + const VAL: /* Type */ = "hi".to_owned();
LL ~ match foo {
LL ~ Foo(VAL) => true,
|
help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
|
LL | Foo(const { "hi".to_owned() }) => true,
| +++++++ +
error: expected a pattern, found an expression
--> $DIR/recover-pat-issues.rs:14:20
|
LL | Bar { baz: "hi".to_owned() } => true,
| ^^^^^^^^^^^^^^^ 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
|
LL | Bar { baz } if baz == "hi".to_owned() => true,
| ~~~ +++++++++++++++++++++++++
help: consider extracting the expression into a `const`
|
LL + const BAZ: /* Type */ = "hi".to_owned();
LL ~ match bar {
LL ~ Bar { baz: BAZ } => true,
|
help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
|
LL | Bar { baz: const { "hi".to_owned() } } => true,
| +++++++ +
error: expected a pattern, found an expression
--> $DIR/recover-pat-issues.rs:25:11
|
LL | &["foo".to_string()] => {}
| ^^^^^^^^^^^^^^^^^ 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
|
LL | &[val] if val == "foo".to_string() => {}
| ~~~ +++++++++++++++++++++++++++
help: consider extracting the expression into a `const`
|
LL + const VAL: /* Type */ = "foo".to_string();
LL ~ match foo.as_slice() {
LL ~ &[VAL] => {}
|
help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
|
LL | &[const { "foo".to_string() }] => {}
| +++++++ +
error: expected a pattern, found an expression
--> $DIR/recover-pat-issues.rs:36:17
|
LL | if let Some(MAGIC.0 as usize) = None::<usize> {}
| ^^^^^^^^^^^^^^^^ 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`
|
LL + const VAL: /* Type */ = MAGIC.0 as usize;
LL ~ if let Some(VAL) = None::<usize> {}
|
help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
|
LL | if let Some(const { MAGIC.0 as usize }) = None::<usize> {}
| +++++++ +
error: expected a pattern, found an expression
--> $DIR/recover-pat-issues.rs:41:13
|
LL | if let (-1.some(4)) = (0, Some(4)) {}
| ^^^^^^^^^^ 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`
|
LL + const VAL: /* Type */ = -1.some(4);
LL ~ if let (VAL) = (0, Some(4)) {}
|
help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
|
LL | if let (const { -1.some(4) }) = (0, Some(4)) {}
| +++++++ +
error: expected a pattern, found an expression
--> $DIR/recover-pat-issues.rs:44:13
|
LL | if let (-1.Some(4)) = (0, Some(4)) {}
| ^^^^^^^^^^ 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`
|
LL + const VAL: /* Type */ = -1.Some(4);
LL ~ if let (VAL) = (0, Some(4)) {}
|
help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
|
LL | if let (const { -1.Some(4) }) = (0, Some(4)) {}
| +++++++ +
error: aborting due to 6 previous errors