Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

@fmease fmease Mar 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to say that this is too coarse-grained since it leads to us no longer flagging (0).match {} or (f()).match {} but after a quick check I realized that we currently don't flag (f()).await, (0).f() and (f()).g() either.

I'm gonna add an item to my TODO list to open an issue for all of these cases unless there already exists one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd prefer if those were implemented in a principled way. This PR doesn't add more inconsistency.

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 };
}