about summary refs log tree commit diff
path: root/tests/ui/half-open-range-patterns
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/half-open-range-patterns
parentc2047219b59ac7830c4315653858f28cf0d57b9d (diff)
downloadrust-db09345ef6e7f39110704e6196bb239d8f10fc27.tar.gz
rust-db09345ef6e7f39110704e6196bb239d8f10fc27.zip
Add suggestions for expressions in patterns
Diffstat (limited to 'tests/ui/half-open-range-patterns')
-rw-r--r--tests/ui/half-open-range-patterns/range_pat_interactions1.stderr11
-rw-r--r--tests/ui/half-open-range-patterns/range_pat_interactions2.stderr23
2 files changed, 28 insertions, 6 deletions
diff --git a/tests/ui/half-open-range-patterns/range_pat_interactions1.stderr b/tests/ui/half-open-range-patterns/range_pat_interactions1.stderr
index c14021e009b..9831348de75 100644
--- a/tests/ui/half-open-range-patterns/range_pat_interactions1.stderr
+++ b/tests/ui/half-open-range-patterns/range_pat_interactions1.stderr
@@ -3,6 +3,17 @@ error: expected a pattern range bound, found an expression
    |
 LL |             0..5+1 => errors_only.push(x),
    |                ^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider extracting the expression into a `const`
+   |
+LL +         const VAL: /* Type */ = 5+1;
+LL ~         match x as i32 {
+LL ~             0..VAL => errors_only.push(x),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |             0..const { 5+1 } => errors_only.push(x),
+   |                +++++++     +
 
 error[E0408]: variable `n` is not bound in all patterns
   --> $DIR/range_pat_interactions1.rs:10:25
diff --git a/tests/ui/half-open-range-patterns/range_pat_interactions2.stderr b/tests/ui/half-open-range-patterns/range_pat_interactions2.stderr
index 136296fa5b0..1b5e875cccb 100644
--- a/tests/ui/half-open-range-patterns/range_pat_interactions2.stderr
+++ b/tests/ui/half-open-range-patterns/range_pat_interactions2.stderr
@@ -1,9 +1,3 @@
-error: expected a pattern range bound, found an expression
-  --> $DIR/range_pat_interactions2.rs:10:18
-   |
-LL |             0..=(5+1) => errors_only.push(x),
-   |                  ^^^ arbitrary expressions are not allowed in patterns
-
 error: range pattern bounds cannot have parentheses
   --> $DIR/range_pat_interactions2.rs:10:17
    |
@@ -16,6 +10,23 @@ LL -             0..=(5+1) => errors_only.push(x),
 LL +             0..=5+1 => errors_only.push(x),
    |
 
+error: expected a pattern range bound, found an expression
+  --> $DIR/range_pat_interactions2.rs:10:18
+   |
+LL |             0..=(5+1) => errors_only.push(x),
+   |                  ^^^ arbitrary expressions are not allowed in patterns
+   |
+help: consider extracting the expression into a `const`
+   |
+LL +         const VAL: /* Type */ = 5+1;
+LL ~         match x as i32 {
+LL ~             0..=(VAL) => errors_only.push(x),
+   |
+help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
+   |
+LL |             0..=(const { 5+1 }) => errors_only.push(x),
+   |                  +++++++     +
+
 error[E0658]: inline-const in pattern position is experimental
   --> $DIR/range_pat_interactions2.rs:15:20
    |