Skip to content

Fix unused_parens for pinned reference patterns#156089

Open
P8L1 wants to merge 2 commits intorust-lang:mainfrom
P8L1:fix-unused-parens-pinned-patterns
Open

Fix unused_parens for pinned reference patterns#156089
P8L1 wants to merge 2 commits intorust-lang:mainfrom
P8L1:fix-unused-parens-pinned-patterns

Conversation

@P8L1
Copy link
Copy Markdown

@P8L1 P8L1 commented May 2, 2026

The unused_parens lint previously treated pinned shared-reference patterns like plain shared-reference patterns when deciding whether removing parentheses could change the meaning of a leading mut binding.

That was too conservative for pinned reference patterns such as &pin const (mut x). The pin const part belongs to the outer reference pattern, so removing the inner parentheses still leaves mut x as the subpattern.

This updates the ambiguity check so the leading-mut suppression only applies to plain shared reference patterns. Pinned reference patterns can now receive correct rustfix suggestions.

The patch also broadens the binding check from only plain mut bindings to all binding modes whose binding mutability is Mutability::Mut, covering forms such as mut ref pin const.

Tests cover:

  • &pin const (...)
  • &pin mut (...)
  • mutable bindings under pinned refs
  • mut _x @ _
  • nested pinned reference patterns
  • ref pin const / ref pin mut
  • mut ref pin const / mut ref pin mut
  • pinned or-patterns remaining suppressed
  • plain shared &(mut ...) cases remaining suppressed

@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 May 2, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 2, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 21 candidates

@Kivooeo
Copy link
Copy Markdown
Member

Kivooeo commented May 3, 2026

same as here: #156087 (comment)

@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 3, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 3, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 3, 2026
@P8L1
Copy link
Copy Markdown
Author

P8L1 commented May 3, 2026

same as here: #156087 (comment)

@rustbot author

I gated the pinned-pattern unused-parens rustfix path on pin_ergonomics, so it is only emitted for crates that opted into the feature. I also left a FIXME next to the gate saying to remove it once pin_ergonomics is stabilized.

@P8L1
Copy link
Copy Markdown
Author

P8L1 commented May 3, 2026

@rustbot ready

Addressed the review feedback by gating the pinned-pattern unused_parens rustfix path on pin_ergonomics, so it is only emitted for crates that opted into the feature.

I also added a FIXME next to the gate saying to remove it once pin_ergonomics is stabilized.

@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 May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants