about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-12-28 17:54:35 +0000
committerbors <bors@rust-lang.org>2023-12-28 17:54:35 +0000
commit3ee671095499d83ba18d510683fa2a784d7d2ad2 (patch)
tree27c97142153699881c96f3c736b173501deef6dd /compiler/rustc_parse/src/parser/expr.rs
parentf4d794ea0b845413344621d89f6c945062748485 (diff)
parente8831b6df892887862505d356b436d0e1ff506b0 (diff)
downloadrust-3ee671095499d83ba18d510683fa2a784d7d2ad2.tar.gz
rust-3ee671095499d83ba18d510683fa2a784d7d2ad2.zip
Auto merge of #119384 - matthiaskrgr:rollup-hhz9ws0, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #119331 (rustdoc-search: count path edits with separate edit limit)
 - #119359 (Simplify Parser::ident_or_error)
 - #119376 (Add regression test for #106630)
 - #119379 (Update `parse_seq` doc)
 - #119380 (Don't suggest writing a bodyless arm if the pattern can never be a never pattern)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 73bd19f34c1..bf6151b64d3 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -2937,7 +2937,13 @@ impl<'a> Parser<'a> {
             let is_almost_fat_arrow = TokenKind::FatArrow
                 .similar_tokens()
                 .is_some_and(|similar_tokens| similar_tokens.contains(&this.token.kind));
-            let mut result = if !is_fat_arrow && !is_almost_fat_arrow {
+
+            // this avoids the compiler saying that a `,` or `}` was expected even though
+            // the pattern isn't a never pattern (and thus an arm body is required)
+            let armless = (!is_fat_arrow && !is_almost_fat_arrow && pat.could_be_never_pattern())
+                || matches!(this.token.kind, token::Comma | token::CloseDelim(Delimiter::Brace));
+
+            let mut result = if armless {
                 // A pattern without a body, allowed for never patterns.
                 arm_body = None;
                 this.expect_one_of(&[token::Comma], &[token::CloseDelim(Delimiter::Brace)]).map(