False positive for `clippy::needless_borrows_for_generic_args`

Open
#16,538 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
devtools

Research direction

Start by running the linked Rust Playground reproducer with Clippy and inspect the implementation and tests for the needless_borrows_for_generic_args lint. Confirm why removing the mutable borrow changes the built-in array behavior, then add coverage showing that this case should not produce a warning.

Written by the indexing model from the issue text.

Description

C-bug I-false-positive
Summary

Following Clippy's suggestion and removing &mut from &mut data would lead to data (which is a built-in arrray) being copied instead of being mutated.

See also https://users.rust-lang.org/t/false-positive-for-clippy-needless-borrows-for-generic-args/138147.

Lint Name

needless_borrows_for_generic_args

Reproducer

Go to https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=5f88142da1ad985c8da2d12c22a7bac9 and run Clippy.

I saw this happen:

warning: the borrowed expression implements the required traits
  --> src/main.rs:10:13
   |
10 |     process(&mut data);
   |             ^^^^^^^^^ help: change this to: `data`
   |

I expected to see this happen:

no warning

Version

Additional Labels

No response

Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-lang/rust-clippy

All issues in rust-lang/rust-clippy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.