diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index 852eedf36cf9d..b7b47f57ff3df 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -791,11 +791,11 @@ parse_unexpected_expr_in_pat = .label = arbitrary expressions are not allowed in patterns -parse_unexpected_expr_in_pat_const_sugg = extract the expression into a `const` and refer to it +parse_unexpected_expr_in_pat_const_sugg = consider extracting the expression into a `const` -parse_unexpected_expr_in_pat_create_guard_sugg = check the value in an arm guard +parse_unexpected_expr_in_pat_create_guard_sugg = consider moving the expression to a match arm guard -parse_unexpected_expr_in_pat_inline_const_sugg = wrap the expression in a inline const (requires `{"#"}![feature(inline_const_pat)]`) +parse_unexpected_expr_in_pat_inline_const_sugg = consider wrapping the expression in an inline `const` (requires `{"#"}![feature(inline_const_pat)]`) parse_unexpected_expr_in_pat_remove_let_sugg = remove the `let` if you meant to {$has_initializer -> @@ -803,7 +803,7 @@ parse_unexpected_expr_in_pat_remove_let_sugg = *[false] evaluate an expression } -parse_unexpected_expr_in_pat_update_guard_sugg = check the value in the arm guard +parse_unexpected_expr_in_pat_update_guard_sugg = consider moving the expression to the match arm guard parse_unexpected_if_with_if = unexpected `if` in the condition expression .suggestion = remove the `if` diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index b0d0574499717..0c40958e5d5b5 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -2630,7 +2630,8 @@ pub(crate) enum UnexpectedExpressionInPatternSugg { #[suggestion_part(code = "{ident}")] ident_span: Span, /// The end of the match arm's pattern. - #[suggestion_part(code = " if {ident} == {expr}")] + // FIXME: only insert `()` if needed + #[suggestion_part(code = " if {ident} == ({expr})")] pat_hi: Span, /// The suggested identifier. ident: String, @@ -2650,7 +2651,8 @@ pub(crate) enum UnexpectedExpressionInPatternSugg { #[suggestion_part(code = "(")] guard_lo: Span, /// The end of the match arm guard's expression. - #[suggestion_part(code = ") && {ident} == {expr}")] + // FIXME: only insert `()` if needed + #[suggestion_part(code = ") && {ident} == ({expr})")] guard_hi: Span, /// The suggested identifier. ident: String, @@ -2664,7 +2666,7 @@ pub(crate) enum UnexpectedExpressionInPatternSugg { )] Const { /// The beginning of statement's line. - #[suggestion_part(code = "{indentation}const {ident}: _ = {expr};\n")] + #[suggestion_part(code = "{indentation}const {ident}: /* Type */ = {expr};\n")] stmt_lo: Span, /// The span of the `PatKind:Err` to be transformed into a `PatKind::Ident`. #[suggestion_part(code = "{ident}")] 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 0efa21658d639..9831348de7569 100644 --- a/tests/ui/half-open-range-patterns/range_pat_interactions1.stderr +++ b/tests/ui/half-open-range-patterns/range_pat_interactions1.stderr @@ -4,13 +4,13 @@ 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: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = 5+1; +LL + const VAL: /* Type */ = 5+1; LL ~ match x as i32 { LL ~ 0..VAL => errors_only.push(x), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | 0..const { 5+1 } => errors_only.push(x), | +++++++ + 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 d35208d4a1e78..1b5e875cccb68 100644 --- a/tests/ui/half-open-range-patterns/range_pat_interactions2.stderr +++ b/tests/ui/half-open-range-patterns/range_pat_interactions2.stderr @@ -16,13 +16,13 @@ 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: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = 5+1; +LL + const VAL: /* Type */ = 5+1; LL ~ match x as i32 { LL ~ 0..=(VAL) => errors_only.push(x), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | 0..=(const { 5+1 }) => errors_only.push(x), | +++++++ + diff --git a/tests/ui/parser/issues/issue-24375.stderr b/tests/ui/parser/issues/issue-24375.stderr index 0099a29e0abb9..caad7ee123e3d 100644 --- a/tests/ui/parser/issues/issue-24375.stderr +++ b/tests/ui/parser/issues/issue-24375.stderr @@ -4,17 +4,17 @@ error: expected a pattern, found an expression LL | tmp[0] => {} | ^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == tmp[0] => {} - | ~~~ ++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (tmp[0]) => {} + | ~~~ ++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = tmp[0]; +LL + const VAL: /* Type */ = tmp[0]; LL ~ match z { LL ~ VAL => {} | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { tmp[0] } => {} | +++++++ + diff --git a/tests/ui/parser/recover/recover-pat-exprs.stderr b/tests/ui/parser/recover/recover-pat-exprs.stderr index d4c146070ccc3..08b0ad3075014 100644 --- a/tests/ui/parser/recover/recover-pat-exprs.stderr +++ b/tests/ui/parser/recover/recover-pat-exprs.stderr @@ -4,18 +4,18 @@ error: expected a pattern, found an expression LL | x.y => (), | ^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x.y => (), - | ~~~ +++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x.y) => (), + | ~~~ +++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x.y; +LL + const VAL: /* Type */ = x.y; LL ~ match 0 { LL | x => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x.y } => (), | +++++++ + @@ -26,19 +26,19 @@ error: expected a pattern, found an expression LL | x.0 => (), | ^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x.0 => (), - | ~~~ +++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x.0) => (), + | ~~~ +++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x.0; +LL + const VAL: /* Type */ = x.0; LL ~ match 0 { LL | x => (), LL | x.y => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x.0 } => (), | +++++++ + @@ -49,20 +49,20 @@ error: expected a pattern, found an expression LL | x._0 => (), | ^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x._0 => (), - | ~~~ ++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x._0) => (), + | ~~~ ++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x._0; +LL + const VAL: /* Type */ = x._0; LL ~ match 0 { LL | x => (), LL | x.y => (), LL | x.0 => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x._0 } => (), | +++++++ + @@ -73,20 +73,20 @@ error: expected a pattern, found an expression LL | x.0.1 => (), | ^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x.0.1 => (), - | ~~~ +++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x.0.1) => (), + | ~~~ +++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x.0.1; +LL + const VAL: /* Type */ = x.0.1; LL ~ match 0 { LL | x => (), ... LL | x._0 => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x.0.1 } => (), | +++++++ + @@ -97,20 +97,20 @@ error: expected a pattern, found an expression LL | x.4.y.17.__z => (), | ^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x.4.y.17.__z => (), - | ~~~ ++++++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x.4.y.17.__z) => (), + | ~~~ ++++++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x.4.y.17.__z; +LL + const VAL: /* Type */ = x.4.y.17.__z; LL ~ match 0 { LL | x => (), ... LL | x.0.1 => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x.4.y.17.__z } => (), | +++++++ + @@ -151,17 +151,17 @@ error: expected a pattern, found an expression LL | x[0] => (), | ^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x[0] => (), - | ~~~ ++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x[0]) => (), + | ~~~ ++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x[0]; +LL + const VAL: /* Type */ = x[0]; LL ~ match 0 { LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x[0] } => (), | +++++++ + @@ -172,18 +172,18 @@ error: expected a pattern, found an expression LL | x[..] => (), | ^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x[..] => (), - | ~~~ +++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x[..]) => (), + | ~~~ +++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x[..]; +LL + const VAL: /* Type */ = x[..]; LL ~ match 0 { LL | x[0] => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x[..] } => (), | +++++++ + @@ -221,17 +221,17 @@ error: expected a pattern, found an expression LL | x.f() => (), | ^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x.f() => (), - | ~~~ +++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x.f()) => (), + | ~~~ +++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x.f(); +LL + const VAL: /* Type */ = x.f(); LL ~ match 0 { LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x.f() } => (), | +++++++ + @@ -242,18 +242,18 @@ error: expected a pattern, found an expression LL | x._f() => (), | ^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x._f() => (), - | ~~~ ++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x._f()) => (), + | ~~~ ++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x._f(); +LL + const VAL: /* Type */ = x._f(); LL ~ match 0 { LL | x.f() => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x._f() } => (), | +++++++ + @@ -264,19 +264,19 @@ error: expected a pattern, found an expression LL | x? => (), | ^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x? => (), - | ~~~ ++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x?) => (), + | ~~~ ++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x?; +LL + const VAL: /* Type */ = x?; LL ~ match 0 { LL | x.f() => (), LL | x._f() => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x? } => (), | +++++++ + @@ -287,20 +287,20 @@ error: expected a pattern, found an expression LL | ().f() => (), | ^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == ().f() => (), - | ~~~ ++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (().f()) => (), + | ~~~ ++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = ().f(); +LL + const VAL: /* Type */ = ().f(); LL ~ match 0 { LL | x.f() => (), LL | x._f() => (), LL | x? => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { ().f() } => (), | +++++++ + @@ -311,20 +311,20 @@ error: expected a pattern, found an expression LL | (0, x)?.f() => (), | ^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == (0, x)?.f() => (), - | ~~~ +++++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == ((0, x)?.f()) => (), + | ~~~ +++++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = (0, x)?.f(); +LL + const VAL: /* Type */ = (0, x)?.f(); LL ~ match 0 { LL | x.f() => (), ... LL | ().f() => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { (0, x)?.f() } => (), | +++++++ + @@ -335,20 +335,20 @@ error: expected a pattern, found an expression LL | x.f().g() => (), | ^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x.f().g() => (), - | ~~~ +++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x.f().g()) => (), + | ~~~ +++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x.f().g(); +LL + const VAL: /* Type */ = x.f().g(); LL ~ match 0 { LL | x.f() => (), ... LL | (0, x)?.f() => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x.f().g() } => (), | +++++++ + @@ -359,20 +359,20 @@ error: expected a pattern, found an expression LL | 0.f()?.g()?? => (), | ^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == 0.f()?.g()?? => (), - | ~~~ ++++++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (0.f()?.g()??) => (), + | ~~~ ++++++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = 0.f()?.g()??; +LL + const VAL: /* Type */ = 0.f()?.g()??; LL ~ match 0 { LL | x.f() => (), ... LL | x.f().g() => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { 0.f()?.g()?? } => (), | +++++++ + @@ -383,17 +383,17 @@ error: expected a pattern, found an expression LL | x as usize => (), | ^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x as usize => (), - | ~~~ ++++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x as usize) => (), + | ~~~ ++++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x as usize; +LL + const VAL: /* Type */ = x as usize; LL ~ match 0 { LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x as usize } => (), | +++++++ + @@ -404,18 +404,18 @@ error: expected a pattern, found an expression LL | 0 as usize => (), | ^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == 0 as usize => (), - | ~~~ ++++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (0 as usize) => (), + | ~~~ ++++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = 0 as usize; +LL + const VAL: /* Type */ = 0 as usize; LL ~ match 0 { LL | x as usize => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { 0 as usize } => (), | +++++++ + @@ -426,19 +426,19 @@ error: expected a pattern, found an expression LL | x.f().0.4 as f32 => (), | ^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == x.f().0.4 as f32 => (), - | ~~~ ++++++++++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (x.f().0.4 as f32) => (), + | ~~~ ++++++++++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = x.f().0.4 as f32; +LL + const VAL: /* Type */ = x.f().0.4 as f32; LL ~ match 0 { LL | x as usize => (), LL | 0 as usize => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { x.f().0.4 as f32 } => (), | +++++++ + @@ -449,17 +449,17 @@ error: expected a pattern, found an expression LL | 1 + 1 => (), | ^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == 1 + 1 => (), - | ~~~ +++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (1 + 1) => (), + | ~~~ +++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = 1 + 1; +LL + const VAL: /* Type */ = 1 + 1; LL ~ match 0 { LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { 1 + 1 } => (), | +++++++ + @@ -470,18 +470,18 @@ error: expected a pattern, found an expression LL | (1 + 2) * 3 => (), | ^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == (1 + 2) * 3 => (), - | ~~~ +++++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == ((1 + 2) * 3) => (), + | ~~~ +++++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = (1 + 2) * 3; +LL + const VAL: /* Type */ = (1 + 2) * 3; LL ~ match 0 { LL | 1 + 1 => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { (1 + 2) * 3 } => (), | +++++++ + @@ -509,17 +509,17 @@ error: expected a pattern, found an expression LL | u8::MAX.abs() => (), | ^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == u8::MAX.abs() => (), - | ~~~ +++++++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (u8::MAX.abs()) => (), + | ~~~ +++++++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = u8::MAX.abs(); +LL + const VAL: /* Type */ = u8::MAX.abs(); LL ~ match u8::MAX { LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { u8::MAX.abs() } => (), | +++++++ + @@ -530,20 +530,20 @@ error: expected a pattern, found an expression LL | z @ w @ v.u() => (), | ^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | z @ w @ val if val == v.u() => (), - | ~~~ +++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | z @ w @ val if val == (v.u()) => (), + | ~~~ +++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = v.u(); +LL + const VAL: /* Type */ = v.u(); LL ~ match u8::MAX { LL | u8::MAX.abs() => (), ... LL | LL ~ z @ w @ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | z @ w @ const { v.u() } => (), | +++++++ + @@ -554,20 +554,20 @@ error: expected a pattern, found an expression LL | y.ilog(3) => (), | ^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == y.ilog(3) => (), - | ~~~ +++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (y.ilog(3)) => (), + | ~~~ +++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = y.ilog(3); +LL + const VAL: /* Type */ = y.ilog(3); LL ~ match u8::MAX { LL | u8::MAX.abs() => (), ... LL | LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { y.ilog(3) } => (), | +++++++ + @@ -578,20 +578,20 @@ error: expected a pattern, found an expression LL | n + 1 => (), | ^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == n + 1 => (), - | ~~~ +++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (n + 1) => (), + | ~~~ +++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = n + 1; +LL + const VAL: /* Type */ = n + 1; LL ~ match u8::MAX { LL | u8::MAX.abs() => (), ... LL | LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { n + 1 } => (), | +++++++ + @@ -602,20 +602,20 @@ error: expected a pattern, found an expression LL | ("".f() + 14 * 8) => (), | ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | (val) if val == "".f() + 14 * 8 => (), - | ~~~ +++++++++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | (val) if val == ("".f() + 14 * 8) => (), + | ~~~ +++++++++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = "".f() + 14 * 8; +LL + const VAL: /* Type */ = "".f() + 14 * 8; LL ~ match u8::MAX { LL | u8::MAX.abs() => (), ... LL | LL ~ (VAL) => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | (const { "".f() + 14 * 8 }) => (), | +++++++ + @@ -626,20 +626,20 @@ error: expected a pattern, found an expression LL | f?() => (), | ^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | val if val == f?() => (), - | ~~~ ++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | val if val == (f?()) => (), + | ~~~ ++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = f?(); +LL + const VAL: /* Type */ = f?(); LL ~ match u8::MAX { LL | u8::MAX.abs() => (), ... LL | 0 | ((1) | 2) | 3 => (), LL ~ VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { f?() } => (), | +++++++ + diff --git a/tests/ui/parser/recover/recover-pat-issues.stderr b/tests/ui/parser/recover/recover-pat-issues.stderr index 09a707c30ea93..11a6906009ed8 100644 --- a/tests/ui/parser/recover/recover-pat-issues.stderr +++ b/tests/ui/parser/recover/recover-pat-issues.stderr @@ -4,17 +4,17 @@ error: expected a pattern, found an expression LL | Foo("hi".to_owned()) => true, | ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | Foo(val) if val == "hi".to_owned() => true, - | ~~~ +++++++++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | Foo(val) if val == ("hi".to_owned()) => true, + | ~~~ +++++++++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = "hi".to_owned(); +LL + const VAL: /* Type */ = "hi".to_owned(); LL ~ match foo { LL ~ Foo(VAL) => true, | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | Foo(const { "hi".to_owned() }) => true, | +++++++ + @@ -25,17 +25,17 @@ error: expected a pattern, found an expression LL | Bar { baz: "hi".to_owned() } => true, | ^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | Bar { baz } if baz == "hi".to_owned() => true, - | ~~~ +++++++++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | Bar { baz } if baz == ("hi".to_owned()) => true, + | ~~~ +++++++++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const BAZ: _ = "hi".to_owned(); +LL + const BAZ: /* Type */ = "hi".to_owned(); LL ~ match bar { LL ~ Bar { baz: BAZ } => true, | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | Bar { baz: const { "hi".to_owned() } } => true, | +++++++ + @@ -46,17 +46,17 @@ error: expected a pattern, found an expression LL | &["foo".to_string()] => {} | ^^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: check the value in an arm guard +help: consider moving the expression to a match arm guard | -LL | &[val] if val == "foo".to_string() => {} - | ~~~ +++++++++++++++++++++++++++ -help: extract the expression into a `const` and refer to it +LL | &[val] if val == ("foo".to_string()) => {} + | ~~~ +++++++++++++++++++++++++++++ +help: consider extracting the expression into a `const` | -LL + const VAL: _ = "foo".to_string(); +LL + const VAL: /* Type */ = "foo".to_string(); LL ~ match foo.as_slice() { LL ~ &[VAL] => {} | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | &[const { "foo".to_string() }] => {} | +++++++ + @@ -67,12 +67,12 @@ error: expected a pattern, found an expression LL | if let Some(MAGIC.0 as usize) = None:: {} | ^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = MAGIC.0 as usize; +LL + const VAL: /* Type */ = MAGIC.0 as usize; LL ~ if let Some(VAL) = None:: {} | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | if let Some(const { MAGIC.0 as usize }) = None:: {} | +++++++ + @@ -83,12 +83,12 @@ error: expected a pattern, found an expression LL | if let (-1.some(4)) = (0, Some(4)) {} | ^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = -1.some(4); +LL + const VAL: /* Type */ = -1.some(4); LL ~ if let (VAL) = (0, Some(4)) {} | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | if let (const { -1.some(4) }) = (0, Some(4)) {} | +++++++ + @@ -99,12 +99,12 @@ error: expected a pattern, found an expression LL | if let (-1.Some(4)) = (0, Some(4)) {} | ^^^^^^^^^^ arbitrary expressions are not allowed in patterns | -help: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = -1.Some(4); +LL + const VAL: /* Type */ = -1.Some(4); LL ~ if let (VAL) = (0, Some(4)) {} | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | if let (const { -1.Some(4) }) = (0, Some(4)) {} | +++++++ + diff --git a/tests/ui/parser/recover/recover-pat-lets.stderr b/tests/ui/parser/recover/recover-pat-lets.stderr index 1bffbba5c19f8..114f60ae2d5cb 100644 --- a/tests/ui/parser/recover/recover-pat-lets.stderr +++ b/tests/ui/parser/recover/recover-pat-lets.stderr @@ -40,12 +40,12 @@ error: expected a pattern, found an expression LL | let Some(1 + 1) = x else { | ^^^^^ arbitrary expressions are not allowed in patterns | -help: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = 1 + 1; +LL + const VAL: /* Type */ = 1 + 1; LL ~ let Some(VAL) = x else { | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | let Some(const { 1 + 1 }) = x else { | +++++++ + @@ -56,12 +56,12 @@ error: expected a pattern, found an expression LL | if let Some(1 + 1) = x { | ^^^^^ arbitrary expressions are not allowed in patterns | -help: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = 1 + 1; +LL + const VAL: /* Type */ = 1 + 1; LL ~ if let Some(VAL) = x { | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | if let Some(const { 1 + 1 }) = x { | +++++++ + diff --git a/tests/ui/parser/recover/recover-pat-ranges.stderr b/tests/ui/parser/recover/recover-pat-ranges.stderr index 3ebe964c7735e..088f83b0ccbac 100644 --- a/tests/ui/parser/recover/recover-pat-ranges.stderr +++ b/tests/ui/parser/recover/recover-pat-ranges.stderr @@ -88,16 +88,16 @@ error: expected a pattern range bound, found an expression LL | ..=1 + 2 => (), | ^^^^^ arbitrary expressions are not allowed in patterns | -help: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = 1 + 2; +LL + const VAL: /* Type */ = 1 + 2; LL ~ match -1 { LL | 0..=1 => (), ... LL | LL ~ ..=VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | ..=const { 1 + 2 } => (), | +++++++ + @@ -108,16 +108,16 @@ error: expected a pattern range bound, found an expression LL | (-4 + 0).. => (), | ^^^^^^ arbitrary expressions are not allowed in patterns | -help: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = -4 + 0; +LL + const VAL: /* Type */ = -4 + 0; LL ~ match -1 { LL | 0..=1 => (), ... LL | LL ~ (VAL).. => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | (const { -4 + 0 }).. => (), | +++++++ + @@ -128,16 +128,16 @@ error: expected a pattern range bound, found an expression LL | (1 + 4)...1 * 2 => (), | ^^^^^ arbitrary expressions are not allowed in patterns | -help: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = 1 + 4; +LL + const VAL: /* Type */ = 1 + 4; LL ~ match -1 { LL | 0..=1 => (), ... LL | LL ~ (VAL)...1 * 2 => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | (const { 1 + 4 })...1 * 2 => (), | +++++++ + @@ -148,16 +148,16 @@ error: expected a pattern range bound, found an expression LL | (1 + 4)...1 * 2 => (), | ^^^^^ arbitrary expressions are not allowed in patterns | -help: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = 1 * 2; +LL + const VAL: /* Type */ = 1 * 2; LL ~ match -1 { LL | 0..=1 => (), ... LL | LL ~ (1 + 4)...VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | (1 + 4)...const { 1 * 2 } => (), | +++++++ + @@ -168,16 +168,16 @@ error: expected a pattern range bound, found an expression LL | 0.x()..="y".z() => (), | ^^^^^ arbitrary expressions are not allowed in patterns | -help: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = 0.x(); +LL + const VAL: /* Type */ = 0.x(); LL ~ match -1 { LL | 0..=1 => (), ... LL | LL ~ VAL..="y".z() => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | const { 0.x() }..="y".z() => (), | +++++++ + @@ -188,16 +188,16 @@ error: expected a pattern range bound, found an expression LL | 0.x()..="y".z() => (), | ^^^^^^^ arbitrary expressions are not allowed in patterns | -help: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = "y".z(); +LL + const VAL: /* Type */ = "y".z(); LL ~ match -1 { LL | 0..=1 => (), ... LL | LL ~ 0.x()..=VAL => (), | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | 0.x()..=const { "y".z() } => (), | +++++++ + diff --git a/tests/ui/parser/recover/recover-pat-wildcards.stderr b/tests/ui/parser/recover/recover-pat-wildcards.stderr index 7286e5646577b..30307726a973b 100644 --- a/tests/ui/parser/recover/recover-pat-wildcards.stderr +++ b/tests/ui/parser/recover/recover-pat-wildcards.stderr @@ -77,13 +77,13 @@ error: expected a pattern range bound, found an expression LL | 4..=(2 + _) => () | ^^^^^ arbitrary expressions are not allowed in patterns | -help: extract the expression into a `const` and refer to it +help: consider extracting the expression into a `const` | -LL + const VAL: _ = 2 + _; +LL + const VAL: /* Type */ = 2 + _; LL ~ match 9 { LL ~ 4..=(VAL) => () | -help: wrap the expression in a inline const (requires `#![feature(inline_const_pat)]`) +help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | LL | 4..=(const { 2 + _ }) => () | +++++++ +