about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-02-23 02:44:19 -0500
committerGitHub <noreply@github.com>2025-02-23 02:44:19 -0500
commitda493c91d65454b1c7d0fbd4d62ca5af5498a0b4 (patch)
treec18d9baa37e566112a418d8f7463d556bf1642d2 /compiler/rustc_parse/src
parent4bed9eca0eb578d66be4bc3646b06b290161c9f3 (diff)
parenta8f8b8de66025e254cbed08a53d5084162605d98 (diff)
downloadrust-da493c91d65454b1c7d0fbd4d62ca5af5498a0b4.tar.gz
rust-da493c91d65454b1c7d0fbd4d62ca5af5498a0b4.zip
Rollup merge of #137435 - estebank:match-arm-2, r=compiler-errors
Fix "missing match arm body" suggestion involving `!`

Include the match arm guard in the gated span, so that the suggestion to add a body is correct instead of inserting the body before the guard.

Make the suggestion verbose.

```
error: `match` arm with no body
  --> $DIR/feature-gate-never_patterns.rs:43:9
   |
LL |         Some(_) if false,
   |         ^^^^^^^^^^^^^^^^
   |
help: add a body after the pattern
   |
LL |         Some(_) if false => { todo!() },
   |                          ++++++++++++++
```

r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index e0e6c2177da..b2e58c94280 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -3125,10 +3125,11 @@ impl<'a> Parser<'a> {
             let mut result = if armless {
                 // A pattern without a body, allowed for never patterns.
                 arm_body = None;
+                let span = lo.to(this.prev_token.span);
                 this.expect_one_of(&[exp!(Comma)], &[exp!(CloseBrace)]).map(|x| {
                     // Don't gate twice
                     if !pat.contains_never_pattern() {
-                        this.psess.gated_spans.gate(sym::never_patterns, pat.span);
+                        this.psess.gated_spans.gate(sym::never_patterns, span);
                     }
                     x
                 })