1
Fork 0

Rollup merge of #119380 - ShE3py:match-never-pat, r=petrochenkov

Don't suggest writing a bodyless arm if the pattern can never be a never pattern

#118527 enabled arms to be bodyless for never patterns ; this PR removes the `,` and `}` suggestions for patterns that could never be never patterns.
This commit is contained in:
Matthias Krüger 2023-12-28 18:48:02 +01:00 committed by GitHub
commit e8831b6df8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 32 additions and 26 deletions

View file

@ -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(