Fix unused_parens for pinned reference patterns#156089
Fix unused_parens for pinned reference patterns#156089P8L1 wants to merge 2 commits intorust-lang:mainfrom
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 |
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.Tests cover:
&pin const (...)&pin mut (...)mut _x @ _ref pin const/ref pin mutmut ref pin const/mut ref pin mut&(mut ...)cases remaining suppressed