mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
![]() Further improve diagnostics for expressions in pattern position Follow-up of #118625, see #121697. ```rs fn main() { match 'b' { y.0.0.1.z().f()? as u32 => {}, } } ``` Before: ``` error: expected one of `=>`, ``@`,` `if`, or `|`, found `.` --> src/main.rs:3:10 | 3 | y.0.0.1.z().f()? as u32 => {}, | ^ expected one of `=>`, ``@`,` `if`, or `|` ``` After: ``` error: expected a pattern, found an expression --> src/main.rs:3:9 | 3 | y.0.0.1.z().f()? as u32 => {}, | ^^^^^^^^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns | help: consider moving the expression to a match arm guard | 3 | val if val == y.0.0.1.z().f()? as u32 => {}, | ~~~ +++++++++++++++++++++++++++++++++ help: consider extracting the expression into a `const` | 2 + const VAL: /* Type */ = y.0.0.1.z().f()? as u32; 3 ~ match 'b' { 4 ~ VAL => {}, | help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`) | 3 | const { y.0.0.1.z().f()? as u32 } => {}, | +++++++ + ``` --- r? fmease `@rustbot` label +A-diagnostics +A-parser +A-patterns +C-enhancement |
||
---|---|---|
.. | ||
assembly | ||
auxiliary | ||
codegen | ||
codegen-units | ||
coverage | ||
coverage-run-rustdoc | ||
crashes | ||
debuginfo | ||
incremental | ||
mir-opt | ||
pretty | ||
run-make | ||
run-pass-valgrind | ||
rustdoc | ||
rustdoc-gui | ||
rustdoc-js | ||
rustdoc-js-std | ||
rustdoc-json | ||
rustdoc-ui | ||
ui | ||
ui-fulldeps | ||
COMPILER_TESTS.md |