Fix unused_parens for pinned reference patterns#156089
Conversation
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
same as here: #156087 (comment) @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
I gated the pinned-pattern unused-parens rustfix path on |
|
@rustbot ready Addressed the review feedback by gating the pinned-pattern unused_parens rustfix path on I also added a FIXME next to the gate saying to remove it once |
|
r? @Kivooeo |
|
@Kivooeo Please review this as well |
|
it's been only two days since it's open, review may take up to two weeks since i'm pretty busy with other stuff i'd ask you to wait, because it may take a little longer |
|
Hey @Kivooeo, just wanted to gently bump this since it’s been about two weeks. I think I’ve addressed the previous feedback, but please let me know if there’s anything else you’d like changed. Thanks! |
This comment has been minimized.
This comment has been minimized.
696ca4a to
582523b
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. |
|
@Kivooeo ready |
582523b to
ffe1dba
Compare
|
@Kivooeo Hi, sorry for the ping, it's been another 2 weeks. Is there a chance you could have another look? I have addressed the nits |
|
I'll review today-tomorrow |
|
Got very busy today, will review tomorrow 100%, sorry for a delay |
Ok thanks so much, I appreciate you! |
| PatKind::Or(..) if avoid_or => return, | ||
| // Avoid `mut x` and `mut x @ p` if we should: | ||
| PatKind::Ident(BindingMode::MUT, ..) if avoid_mut => { | ||
| // Avoid bindings that start with `mut`, like `mut x`, `mut x @ p`, |
There was a problem hiding this comment.
question regarding this comment and then merge: "start with mut" wording, what about patterns like ref mut for example? is that going to work?
There was a problem hiding this comment.
Yes, "ref mut" should still work here.
This branch is checking the binding’s own mutability ("BindingMode(, Mutability::Mut)"), not the mutability in "ByRef". "ref mut" is represented as "BindingMode(ByRef::Yes(, Mutability::Mut), Mutability::Not)", so it does not match this case.
The wording is a bit imprecise though. I can reword the comment to say “bindings with binding mutability” instead of “bindings that start with "mut"”.

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
mutbinding.That was too conservative for pinned reference patterns such as
&pin const (mut x). Thepin constpart belongs to the outer reference pattern, so removing the inner parentheses still leavesmut xas the subpattern.This updates the ambiguity check so the leading-
mutsuppression 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
mutbindings to all binding modes whose binding mutability isMutability::Mut, covering forms such asmut ref pin const.@rustbot label F-pin_ergonomics