about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-09-19 00:36:33 +0000
committerbors <bors@rust-lang.org>2024-09-19 00:36:33 +0000
commitdf7f77811c8806f85522a38878c57fde221138c9 (patch)
treec0677a7e32bb7882ffcb52150af707d34dbd6c0f /compiler/rustc_codegen_llvm
parenta5cf8bbd4e1c8edeae08778c85c6f806dd00e853 (diff)
parentdb09345ef6e7f39110704e6196bb239d8f10fc27 (diff)
downloadrust-df7f77811c8806f85522a38878c57fde221138c9.tar.gz
rust-df7f77811c8806f85522a38878c57fde221138c9.zip
Auto merge of #123877 - ShE3py:expr-in-pats-2, r=fmease
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
Diffstat (limited to 'compiler/rustc_codegen_llvm')
0 files changed, 0 insertions, 0 deletions