about summary refs log tree commit diff
path: root/tests/ui/parser
diff options
context:
space:
mode:
authorLieselotte <52315535+she3py@users.noreply.github.com>2024-09-18 20:38:43 +0200
committerLieselotte <52315535+she3py@users.noreply.github.com>2024-09-18 20:38:43 +0200
commitdb09345ef6e7f39110704e6196bb239d8f10fc27 (patch)
treea0374ff643b776d21bb32c07aa4cb88631c4d2b5 /tests/ui/parser
parentc2047219b59ac7830c4315653858f28cf0d57b9d (diff)
downloadrust-db09345ef6e7f39110704e6196bb239d8f10fc27.tar.gz
rust-db09345ef6e7f39110704e6196bb239d8f10fc27.zip
Add suggestions for expressions in patterns
Diffstat (limited to 'tests/ui/parser')
-rw-r--r--tests/ui/parser/issues/issue-24375.stderr15
-rw-r--r--tests/ui/parser/pat-lt-bracket-6.stderr4
-rw-r--r--tests/ui/parser/recover/recover-pat-exprs.rs10
-rw-r--r--tests/ui/parser/recover/recover-pat-exprs.stderr569
-rw-r--r--tests/ui/parser/recover/recover-pat-issues.stderr75
-rw-r--r--tests/ui/parser/recover/recover-pat-lets.stderr20
-rw-r--r--tests/ui/parser/recover/recover-pat-ranges.stderr120
-rw-r--r--tests/ui/parser/recover/recover-pat-wildcards.stderr23
8 files changed, 781 insertions, 55 deletions
diff --git a/tests/ui/parser/issues/issue-24375.stderr b/tests/ui/parser/issues/issue-24375.stderr
index e6ef07d13fd..a25c277d78a 100644
--- a/tests/ui/parser/issues/issue-24375.stderr
+++ b/tests/ui/parser/issues/issue-24375.stderr
@@ -3,6 +3,21 @@ error: expected a pattern, found an expression
    |
 LL |         tmp[0] => {}
    |         ^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == tmp[0] => {}
+   |         ~~~ ++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = tmp[0];
+LL ~     match z {
+LL ~         VAL => {}
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { tmp[0] } => {}
+   |         +++++++        +
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/parser/pat-lt-bracket-6.stderr b/tests/ui/parser/pat-lt-bracket-6.stderr
index 10c638a63e4..892883c4aed 100644
--- a/tests/ui/parser/pat-lt-bracket-6.stderr
+++ b/tests/ui/parser/pat-lt-bracket-6.stderr
@@ -1,8 +1,8 @@
 error: expected a pattern, found an expression
-  --> $DIR/pat-lt-bracket-6.rs:5:15
+  --> $DIR/pat-lt-bracket-6.rs:5:14
    |
 LL |     let Test(&desc[..]) = x;
-   |               ^^^^^^^^ arbitrary expressions are not allowed in patterns
+   |              ^^^^^^^^^ arbitrary expressions are not allowed in patterns
 
 error[E0308]: mismatched types
   --> $DIR/pat-lt-bracket-6.rs:10:30
diff --git a/tests/ui/parser/recover/recover-pat-exprs.rs b/tests/ui/parser/recover/recover-pat-exprs.rs
index 031e49cb8eb..e5e25df0c01 100644
--- a/tests/ui/parser/recover/recover-pat-exprs.rs
+++ b/tests/ui/parser/recover/recover-pat-exprs.rs
@@ -53,13 +53,21 @@ fn type_cast() {
     }
 }
 
-// ArithmeticOrLogicalExpression
+// ArithmeticOrLogicalExpression, also check if parentheses are added as needed
 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
+        x.0 > 2 => (), //~ error: expected a pattern, found an expression
+        x.0 == 2 => (), //~ error: expected a pattern, found an expression
+    }
+
+    // preexisting match arm guard
+    match (0, 0) {
+        (x, y.0 > 2) if x != 0 => (), //~ error: expected a pattern, found an expression
+        (x, y.0 > 2) if x != 0 || x != 1 => (), //~ error: expected a pattern, found an expression
     }
 }
 
diff --git a/tests/ui/parser/recover/recover-pat-exprs.stderr b/tests/ui/parser/recover/recover-pat-exprs.stderr
index ea8d1458d27..63956f35c07 100644
--- a/tests/ui/parser/recover/recover-pat-exprs.stderr
+++ b/tests/ui/parser/recover/recover-pat-exprs.stderr
@@ -3,30 +3,117 @@ error: expected a pattern, found an expression
    |
 LL |         x.y => (),
    |         ^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x.y => (),
+   |         ~~~ +++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x.y;
+LL ~     match 0 {
+LL |         x => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x.y } => (),
+   |         +++++++     +
 
 error: expected a pattern, found an expression
   --> $DIR/recover-pat-exprs.rs:6:9
    |
 LL |         x.0 => (),
    |         ^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x.0 => (),
+   |         ~~~ +++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x.0;
+LL ~     match 0 {
+LL |         x => (),
+LL |         x.y => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x.0 } => (),
+   |         +++++++     +
 
 error: expected a pattern, found an expression
   --> $DIR/recover-pat-exprs.rs:7:9
    |
 LL |         x._0 => (),
    |         ^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x._0 => (),
+   |         ~~~ ++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x._0;
+LL ~     match 0 {
+LL |         x => (),
+LL |         x.y => (),
+LL |         x.0 => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x._0 } => (),
+   |         +++++++      +
 
 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
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x.0.1 => (),
+   |         ~~~ +++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x.0.1;
+LL ~     match 0 {
+LL |         x => (),
+...
+LL |         x._0 => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x.0.1 } => (),
+   |         +++++++       +
 
 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
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x.4.y.17.__z => (),
+   |         ~~~ ++++++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x.4.y.17.__z;
+LL ~     match 0 {
+LL |         x => (),
+...
+LL |         x.0.1 => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x.4.y.17.__z } => (),
+   |         +++++++              +
 
 error: expected one of `:`, `;`, `=`, `@`, or `|`, found `.`
   --> $DIR/recover-pat-exprs.rs:12:12
@@ -63,12 +150,43 @@ error: expected a pattern, found an expression
    |
 LL |         x[0] => (),
    |         ^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x[0] => (),
+   |         ~~~ ++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x[0];
+LL ~     match 0 {
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x[0] } => (),
+   |         +++++++      +
 
 error: expected a pattern, found an expression
   --> $DIR/recover-pat-exprs.rs:24:9
    |
 LL |         x[..] => (),
    |         ^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x[..] => (),
+   |         ~~~ +++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x[..];
+LL ~     match 0 {
+LL |         x[0] => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x[..] } => (),
+   |         +++++++       +
 
 error: expected one of `:`, `;`, `=`, `@`, or `|`, found `[`
   --> $DIR/recover-pat-exprs.rs:27:12
@@ -102,99 +220,365 @@ error: expected a pattern, found an expression
    |
 LL |         x.f() => (),
    |         ^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x.f() => (),
+   |         ~~~ +++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x.f();
+LL ~     match 0 {
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x.f() } => (),
+   |         +++++++       +
 
 error: expected a pattern, found an expression
   --> $DIR/recover-pat-exprs.rs:38:9
    |
 LL |         x._f() => (),
    |         ^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x._f() => (),
+   |         ~~~ ++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x._f();
+LL ~     match 0 {
+LL |         x.f() => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x._f() } => (),
+   |         +++++++        +
 
 error: expected a pattern, found an expression
   --> $DIR/recover-pat-exprs.rs:39:9
    |
 LL |         x? => (),
    |         ^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x? => (),
+   |         ~~~ ++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x?;
+LL ~     match 0 {
+LL |         x.f() => (),
+LL |         x._f() => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x? } => (),
+   |         +++++++    +
 
 error: expected a pattern, found an expression
   --> $DIR/recover-pat-exprs.rs:40:9
    |
 LL |         ().f() => (),
    |         ^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == ().f() => (),
+   |         ~~~ ++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = ().f();
+LL ~     match 0 {
+LL |         x.f() => (),
+LL |         x._f() => (),
+LL |         x? => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { ().f() } => (),
+   |         +++++++        +
 
 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
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == (0, x)?.f() => (),
+   |         ~~~ +++++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = (0, x)?.f();
+LL ~     match 0 {
+LL |         x.f() => (),
+...
+LL |         ().f() => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { (0, x)?.f() } => (),
+   |         +++++++             +
 
 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
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x.f().g() => (),
+   |         ~~~ +++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x.f().g();
+LL ~     match 0 {
+LL |         x.f() => (),
+...
+LL |         (0, x)?.f() => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x.f().g() } => (),
+   |         +++++++           +
 
 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
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == 0.f()?.g()?? => (),
+   |         ~~~ ++++++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = 0.f()?.g()??;
+LL ~     match 0 {
+LL |         x.f() => (),
+...
+LL |         x.f().g() => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { 0.f()?.g()?? } => (),
+   |         +++++++              +
 
 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
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x as usize => (),
+   |         ~~~ ++++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x as usize;
+LL ~     match 0 {
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x as usize } => (),
+   |         +++++++            +
 
 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
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == 0 as usize => (),
+   |         ~~~ ++++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = 0 as usize;
+LL ~     match 0 {
+LL |         x as usize => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { 0 as usize } => (),
+   |         +++++++            +
 
 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
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == x.f().0.4 as f32 => (),
+   |         ~~~ ++++++++++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x.f().0.4 as f32;
+LL ~     match 0 {
+LL |         x as usize => (),
+LL |         0 as usize => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x.f().0.4 as f32 } => (),
+   |         +++++++                  +
 
 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
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == 1 + 1 => (),
+   |         ~~~ +++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = 1 + 1;
+LL ~     match 0 {
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { 1 + 1 } => (),
+   |         +++++++       +
 
 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
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == (1 + 2) * 3 => (),
+   |         ~~~ +++++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = (1 + 2) * 3;
+LL ~     match 0 {
+LL |         1 + 1 => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { (1 + 2) * 3 } => (),
+   |         +++++++             +
 
 error: expected a pattern, found an expression
-  --> $DIR/recover-pat-exprs.rs:67:5
+  --> $DIR/recover-pat-exprs.rs:63:9
    |
-LL |     1 + 2 * PI.cos() => 2,
-   |     ^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
+LL |         x.0 > 2 => (),
+   |         ^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == (x.0 > 2) => (),
+   |         ~~~ +++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x.0 > 2;
+LL ~     match 0 {
+LL |         1 + 1 => (),
+...
+LL |
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x.0 > 2 } => (),
+   |         +++++++         +
 
 error: expected a pattern, found an expression
-  --> $DIR/recover-pat-exprs.rs:73:9
+  --> $DIR/recover-pat-exprs.rs:64:9
    |
-LL |         u8::MAX.abs() => (),
-   |         ^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
+LL |         x.0 == 2 => (),
+   |         ^^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == (x.0 == 2) => (),
+   |         ~~~ ++++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = x.0 == 2;
+LL ~     match 0 {
+LL |         1 + 1 => (),
+...
+LL |         x.0 > 2 => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { x.0 == 2 } => (),
+   |         +++++++          +
 
 error: expected a pattern, found an expression
-  --> $DIR/recover-pat-exprs.rs:75:9
+  --> $DIR/recover-pat-exprs.rs:69:13
    |
-LL |         x.sqrt() @ .. => (),
-   |         ^^^^^^^^ arbitrary expressions are not allowed in patterns
+LL |         (x, y.0 > 2) if x != 0 => (),
+   |             ^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to the match arm guard
+   |
+LL |         (x, val) if x != 0 && val == (y.0 > 2) => (),
+   |             ~~~            +++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = y.0 > 2;
+LL ~     match (0, 0) {
+LL ~         (x, VAL) if x != 0 => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         (x, const { y.0 > 2 }) if x != 0 => (),
+   |             +++++++         +
+
+error: expected a pattern, found an expression
+  --> $DIR/recover-pat-exprs.rs:70:13
+   |
+LL |         (x, y.0 > 2) if x != 0 || x != 1 => (),
+   |             ^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to the match arm guard
+   |
+LL |         (x, val) if (x != 0 || x != 1) && val == (y.0 > 2) => (),
+   |             ~~~     +                +++++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = y.0 > 2;
+LL ~     match (0, 0) {
+LL |         (x, y.0 > 2) if x != 0 => (),
+LL ~         (x, VAL) if x != 0 || x != 1 => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         (x, const { y.0 > 2 }) if x != 0 || x != 1 => (),
+   |             +++++++         +
 
 error: left-hand side of `@` must be a binding
-  --> $DIR/recover-pat-exprs.rs:75:9
+  --> $DIR/recover-pat-exprs.rs:83:9
    |
 LL |         x.sqrt() @ .. => (),
    |         --------^^^--
@@ -204,50 +588,161 @@ LL |         x.sqrt() @ .. => (),
    |
    = note: bindings are `x`, `mut x`, `ref x`, and `ref mut x`
 
+error: expected one of `)`, `,`, or `|`, found `+`
+  --> $DIR/recover-pat-exprs.rs:97:12
+   |
+LL |         (_ + 1) => (),
+   |            ^ expected one of `)`, `,`, or `|`
+
+error: expected a pattern, found an expression
+  --> $DIR/recover-pat-exprs.rs:81:9
+   |
+LL |         u8::MAX.abs() => (),
+   |         ^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == u8::MAX.abs() => (),
+   |         ~~~ +++++++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = u8::MAX.abs();
+LL ~     match u8::MAX {
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { u8::MAX.abs() } => (),
+   |         +++++++               +
+
 error: expected a pattern, found an expression
-  --> $DIR/recover-pat-exprs.rs:78:17
+  --> $DIR/recover-pat-exprs.rs:86:17
    |
 LL |         z @ w @ v.u() => (),
    |                 ^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         z @ w @ val if val == v.u() => (),
+   |                 ~~~ +++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = v.u();
+LL ~     match u8::MAX {
+LL |         u8::MAX.abs() => (),
+...
+LL |
+LL ~         z @ w @ VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         z @ w @ const { v.u() } => (),
+   |                 +++++++       +
 
 error: expected a pattern, found an expression
-  --> $DIR/recover-pat-exprs.rs:80:9
+  --> $DIR/recover-pat-exprs.rs:88:9
    |
 LL |         y.ilog(3) => (),
    |         ^^^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == y.ilog(3) => (),
+   |         ~~~ +++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = y.ilog(3);
+LL ~     match u8::MAX {
+LL |         u8::MAX.abs() => (),
+...
+LL |
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { y.ilog(3) } => (),
+   |         +++++++           +
 
 error: expected a pattern, found an expression
-  --> $DIR/recover-pat-exprs.rs:82:9
+  --> $DIR/recover-pat-exprs.rs:90:9
    |
 LL |         n + 1 => (),
    |         ^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == n + 1 => (),
+   |         ~~~ +++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = n + 1;
+LL ~     match u8::MAX {
+LL |         u8::MAX.abs() => (),
+...
+LL |
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { n + 1 } => (),
+   |         +++++++       +
 
 error: expected a pattern, found an expression
-  --> $DIR/recover-pat-exprs.rs:84:10
+  --> $DIR/recover-pat-exprs.rs:92:10
    |
 LL |         ("".f() + 14 * 8) => (),
    |          ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider moving the expression to a match arm guard
+   |
+LL |         (val) if val == "".f() + 14 * 8 => (),
+   |          ~~~  +++++++++++++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = "".f() + 14 * 8;
+LL ~     match u8::MAX {
+LL |         u8::MAX.abs() => (),
+...
+LL |
+LL ~         (VAL) => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         (const { "".f() + 14 * 8 }) => (),
+   |          +++++++                 +
 
 error: expected a pattern, found an expression
-  --> $DIR/recover-pat-exprs.rs:87:9
+  --> $DIR/recover-pat-exprs.rs:95: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 `|`
+help: consider moving the expression to a match arm guard
+   |
+LL |         val if val == f?() => (),
+   |         ~~~ ++++++++++++++
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = f?();
+LL ~     match u8::MAX {
+LL |         u8::MAX.abs() => (),
+...
+LL |         0 | ((1) | 2) | 3 => (),
+LL ~         VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { f?() } => (),
+   |         +++++++      +
 
 error: expected a pattern, found an expression
-  --> $DIR/recover-pat-exprs.rs:93:9
+  --> $DIR/recover-pat-exprs.rs:101: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
+  --> $DIR/recover-pat-exprs.rs:104:28
    |
 LL |     let b = matches!(x, (x * x | x.f()) | x[0]);
    |                            ^ expected one of `)`, `,`, `@`, or `|`
@@ -255,5 +750,23 @@ LL |     let b = matches!(x, (x * x | x.f()) | x[0]);
    |
    = note: while parsing argument for this `pat` macro fragment
 
-error: aborting due to 41 previous errors
+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:75: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:83:9
+   |
+LL |         x.sqrt() @ .. => (),
+   |         ^^^^^^^^ arbitrary expressions are not allowed in patterns
+
+error: aborting due to 45 previous errors
 
diff --git a/tests/ui/parser/recover/recover-pat-issues.stderr b/tests/ui/parser/recover/recover-pat-issues.stderr
index 793091bb1f1..596bff21395 100644
--- a/tests/ui/parser/recover/recover-pat-issues.stderr
+++ b/tests/ui/parser/recover/recover-pat-issues.stderr
@@ -3,36 +3,111 @@ error: expected a pattern, found an expression
    |
 LL |         Foo("hi".to_owned()) => true,
    |             ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+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,
    |                    ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+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()] => {}
    |           ^^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+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> {}
    |                 ^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+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)) {}
    |             ^^^^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+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)) {}
    |             ^^^^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+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
 
diff --git a/tests/ui/parser/recover/recover-pat-lets.stderr b/tests/ui/parser/recover/recover-pat-lets.stderr
index b1d2a9b96d9..e54586b0924 100644
--- a/tests/ui/parser/recover/recover-pat-lets.stderr
+++ b/tests/ui/parser/recover/recover-pat-lets.stderr
@@ -21,12 +21,32 @@ error: expected a pattern, found an expression
    |
 LL |     let Some(1 + 1) = x else {
    |              ^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = 1 + 1;
+LL ~     let Some(VAL) = x else {
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |     let Some(const { 1 + 1 }) = x else {
+   |              +++++++       +
 
 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
+   |
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = 1 + 1;
+LL ~     if let Some(VAL) = x {
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |     if let Some(const { 1 + 1 }) = x {
+   |                 +++++++       +
 
 error: aborting due to 5 previous errors
 
diff --git a/tests/ui/parser/recover/recover-pat-ranges.stderr b/tests/ui/parser/recover/recover-pat-ranges.stderr
index 62ef7a8a908..088f83b0ccb 100644
--- a/tests/ui/parser/recover/recover-pat-ranges.stderr
+++ b/tests/ui/parser/recover/recover-pat-ranges.stderr
@@ -46,12 +46,6 @@ LL -         (0)..=(-4) => (),
 LL +         (0)..=-4 => (),
    |
 
-error: expected a pattern range bound, found an expression
-  --> $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/recover-pat-ranges.rs:13:9
    |
@@ -64,12 +58,6 @@ LL -         (4).. => (),
 LL +         4.. => (),
    |
 
-error: expected a pattern range bound, found an expression
-  --> $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/recover-pat-ranges.rs:15:9
    |
@@ -82,12 +70,6 @@ LL -         (-4 + 0).. => (),
 LL +         -4 + 0.. => (),
    |
 
-error: expected a pattern range bound, found an expression
-  --> $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/recover-pat-ranges.rs:18:9
    |
@@ -101,22 +83,124 @@ LL +         1 + 4...1 * 2 => (),
    |
 
 error: expected a pattern range bound, found an expression
+  --> $DIR/recover-pat-ranges.rs:11:12
+   |
+LL |         ..=1 + 2 => (),
+   |            ^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = 1 + 2;
+LL ~     match -1 {
+LL |         0..=1 => (),
+...
+LL |
+LL ~         ..=VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         ..=const { 1 + 2 } => (),
+   |            +++++++       +
+
+error: expected a pattern range bound, found an expression
+  --> $DIR/recover-pat-ranges.rs:15:10
+   |
+LL |         (-4 + 0).. => (),
+   |          ^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = -4 + 0;
+LL ~     match -1 {
+LL |         0..=1 => (),
+...
+LL |
+LL ~         (VAL).. => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         (const { -4 + 0 }).. => (),
+   |          +++++++        +
+
+error: expected a pattern range bound, found an expression
+  --> $DIR/recover-pat-ranges.rs:18:10
+   |
+LL |         (1 + 4)...1 * 2 => (),
+   |          ^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = 1 + 4;
+LL ~     match -1 {
+LL |         0..=1 => (),
+...
+LL |
+LL ~         (VAL)...1 * 2 => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         (const { 1 + 4 })...1 * 2 => (),
+   |          +++++++       +
+
+error: expected a pattern range bound, found an expression
   --> $DIR/recover-pat-ranges.rs:18:19
    |
 LL |         (1 + 4)...1 * 2 => (),
    |                   ^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = 1 * 2;
+LL ~     match -1 {
+LL |         0..=1 => (),
+...
+LL |
+LL ~         (1 + 4)...VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         (1 + 4)...const { 1 * 2 } => (),
+   |                   +++++++       +
 
 error: expected a pattern range bound, found an expression
   --> $DIR/recover-pat-ranges.rs:24:9
    |
 LL |         0.x()..="y".z() => (),
    |         ^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = 0.x();
+LL ~     match -1 {
+LL |         0..=1 => (),
+...
+LL |
+LL ~         VAL..="y".z() => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         const { 0.x() }..="y".z() => (),
+   |         +++++++       +
 
 error: expected a pattern range bound, found an expression
   --> $DIR/recover-pat-ranges.rs:24:17
    |
 LL |         0.x()..="y".z() => (),
    |                 ^^^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = "y".z();
+LL ~     match -1 {
+LL |         0..=1 => (),
+...
+LL |
+LL ~         0.x()..=VAL => (),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         0.x()..=const { "y".z() } => (),
+   |                 +++++++         +
 
 warning: `...` range patterns are deprecated
   --> $DIR/recover-pat-ranges.rs:18:16
diff --git a/tests/ui/parser/recover/recover-pat-wildcards.stderr b/tests/ui/parser/recover/recover-pat-wildcards.stderr
index 64d477fdeb2..30307726a97 100644
--- a/tests/ui/parser/recover/recover-pat-wildcards.stderr
+++ b/tests/ui/parser/recover/recover-pat-wildcards.stderr
@@ -59,12 +59,6 @@ error: expected one of `=>`, `if`, or `|`, found `(`
 LL |         ..(_) => ()
    |           ^ expected one of `=>`, `if`, or `|`
 
-error: expected a pattern range bound, found an expression
-  --> $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/recover-pat-wildcards.rs:55:13
    |
@@ -77,6 +71,23 @@ LL -         4..=(2 + _) => ()
 LL +         4..=2 + _ => ()
    |
 
+error: expected a pattern range bound, found an expression
+  --> $DIR/recover-pat-wildcards.rs:55:14
+   |
+LL |         4..=(2 + _) => ()
+   |              ^^^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider extracting the expression into a `const`
+   |
+LL +     const VAL: /* Type */ = 2 + _;
+LL ~     match 9 {
+LL ~         4..=(VAL) => ()
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |         4..=(const { 2 + _ }) => ()
+   |              +++++++       +
+
 error: aborting due to 11 previous errors
 
 For more information about this error, try `rustc --explain E0586`.