Skip to content

Commit

Permalink
Rollup merge of rust-lang#123096 - compiler-errors:postfix-match-pare…
Browse files Browse the repository at this point in the history
…ns, 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 rust-lang#123064

r? fmease
  • Loading branch information
matthiaskrgr authored Mar 28, 2024
2 parents 732ded9 + 950b40f commit 69cfe80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/match/postfix-match/no-unused-parens.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ check-pass

#![feature(postfix_match)]

fn main() {
(&1).match { a => a };
(1 + 2).match { b => b };
}

0 comments on commit 69cfe80

Please sign in to comment.