Skip to content

extend needless_borrowed_reference to lint mutable ref patterns#17012

Open
Gri-ffin wants to merge 1 commit into
rust-lang:masterfrom
Gri-ffin:fix-16022
Open

extend needless_borrowed_reference to lint mutable ref patterns#17012
Gri-ffin wants to merge 1 commit into
rust-lang:masterfrom
Gri-ffin:fix-16022

Conversation

@Gri-ffin
Copy link
Copy Markdown
Contributor

@Gri-ffin Gri-ffin commented May 14, 2026

closes #16022

The lint should now also fire over &mut ref mut patterns when the matched reference can be moved instead of reborrowed. This is a bit conservative for now as it only handles cases where:

  • the scrutinee is a simple local variable,
  • the local is not used after the enclosing match/if let,
  • and the pattern is not part of an or pattern or behind another reference pattern

There may be other valid cases but this should cover the straightforward ones without risking incorrect suggestions or complexities.

changelog: [needless_borrowed_reference] now also lints certain &mut ref mut patterns

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

rustbot commented May 14, 2026

r? @samueltardieu

rustbot has assigned @samueltardieu.
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: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, llogiq, samueltardieu

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

needless_borrowed_reference does not handle mutable references

3 participants