Rollup merge of #123096 - compiler-errors:postfix-match-parens, r=fmease

Don't check match scrutinee of postfix match for unused parens

We only check the scrutinees of block-like constructs and a few others (return/index/assign/method calls). Just don't do it for postfix match at all.

Fixes #123064

r? fmease
This commit is contained in:
Matthias Krüger 2024-03-28 17:40:49 +01:00 committed by GitHub
commit 69cfe80834
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -865,7 +865,9 @@ trait UnusedDelimLint {
(iter, UnusedDelimsCtx::ForIterExpr, true, None, Some(body.span.lo()), true)
}
Match(ref head, ..) if Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX => {
Match(ref head, _, ast::MatchKind::Prefix)
if Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX =>
{
let left = e.span.lo() + rustc_span::BytePos(5);
(head, UnusedDelimsCtx::MatchScrutineeExpr, true, Some(left), None, true)
}

View File

@ -0,0 +1,8 @@
//@ check-pass
#![feature(postfix_match)]
fn main() {
(&1).match { a => a };
(1 + 2).match { b => b };
}