dont lint unused parens on a pattern that came from a macro argument - #161728
Conversation
|
maybe r? fmease |
|
@rustbot reroll |
|
Error: Failed to set assignee to
Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip. |
| if_let_pat!(('a' | 'A')); | ||
| nested_pat!((1 | 2)); | ||
| // A leading `..=` is rejected by both fragment specifiers. rust-lang/rust#120737 | ||
| match_pat!((..='a' | 'z')); |
There was a problem hiding this comment.
Do we need additional testing to make sure the lint still triggers in the cases where it's supposed to?
There was a problem hiding this comment.
yes, there are three cases. one per leg of the gate. match_pat!(('a')) for a non-or pattern through a metavariable, body_or_pat!() for an or pattern written in the macro body and let (_x) = 1; as the no macro baseline. each one says what it guards in a comment above it.
one note. that leaves the struct field loop and ForLoop uncovered. struct field is easy. ForLoop costs an unrelated E0005 in the stderr since for ('a' | 'A') in "ab".chars() {} parses and lints before the refutable binding error lands. happy to add either or both.
|
@rustbot ready |
|
@bors r+ |
|
@nnethercote thanks! |
…t, r=nnethercote dont lint unused parens on a pattern that came from a macro argument fixes rust-lang#86959 r? @folkertdev
|
This pull request was unapproved. This PR was contained in a rollup (#163147), which was unapproved. |
parentheses around a pattern passed to a `macro_rules!` metavariable can be required by the matcher even though they are redundant once expanded, so suggesting their removal breaks the macro call. a `$p:pat_param` fragment never accepts a top-level `|` and neither does `$p:pat` before edition 2021. a metavariable keeps the call site syntax context while the code around it keeps the macro definition context, so compare the two and reuse the existing `avoid_or` flag when they differ. parens written inside a macro body share one context and keep linting as before.
917935b to
ff63416
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot ready |
|
@nnethercote rebased |
|
@bors r+ |
Rollup merge of #161728 - Albab-Hasan:unused-parens-macro-pat, r=nnethercote dont lint unused parens on a pattern that came from a macro argument fixes #86959 r? @folkertdev
fixes #86959
r? @folkertdev