Skip to content

dont lint unused parens on a pattern that came from a macro argument - #161728

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
Albab-Hasan:unused-parens-macro-pat
Sep 26, 2026
Merged

rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
Albab-Hasan:unused-parens-macro-pat

Conversation

@Albab-Hasan

Copy link
Copy Markdown
Contributor

fixes #86959

r? @folkertdev

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 25, 2026
@folkertdev

Copy link
Copy Markdown
Contributor

maybe

r? fmease

@rustbot rustbot assigned fmease and unassigned folkertdev Aug 26, 2026
@Albab-Hasan

Albab-Hasan commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor Author

@rustbot reroll

@rustbot

rustbot commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Error: Failed to set assignee to reroll: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@rustbot rustbot assigned nnethercote and unassigned fmease Sep 10, 2026
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'));

@nnethercote nnethercote Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need additional testing to make sure the lint still triggers in the cases where it's supposed to?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@nnethercote nnethercote added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 19, 2026
@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 19, 2026
@nnethercote

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 917935b has been approved by nnethercote

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 22, 2026
@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

@nnethercote thanks!

jhpratt added a commit to jhpratt/rust that referenced this pull request Sep 22, 2026
…t, r=nnethercote

dont lint unused parens on a pattern that came from a macro argument

fixes rust-lang#86959

r? @folkertdev
@jhpratt

jhpratt commented Sep 22, 2026

Copy link
Copy Markdown
Member

@bors r- #163147 (comment)

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 22, 2026
@rust-bors

rust-bors Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#163147), which was unapproved.

View changes since this unapproval

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.
@Albab-Hasan
Albab-Hasan force-pushed the unused-parens-macro-pat branch from 917935b to ff63416 Compare September 26, 2026 11:16
@rustbot

rustbot commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

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.

@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 26, 2026
@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

@nnethercote rebased

@nnethercote

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ff63416 has been tentatively approved by nnethercote

It will be put into the queue for this repository once PR CI succeeds.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 26, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 26, 2026
…uwer

Rollup of 3 pull requests

Successful merges:

 - #161728 (dont lint unused parens on a pattern that came from a macro argument)
 - #161791 (Make dropping an empty BTreeMap free)
 - #163283 (Update expect messages in rust_const_eval)
@rust-bors
rust-bors Bot merged commit f55900d into rust-lang:main Sep 26, 2026
13 checks passed
rust-bors Bot pushed a commit that referenced this pull request Sep 26, 2026
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
@rustbot rustbot added this to the 1.101.0 milestone Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unnecessary parentheses warning for (A | B) as :pat in 2018 edition

6 participants