rust-lang / rust-lang/rust-clippy

needless_borrow suggesting the same fix as exists in code

Open
#7,590 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug E-medium I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Lint name: needless_borrow

I tried this code, which is getting a connection from a deadpool database pool:

let join = CommunityModerator::join(&&context.pool.get().await?, &community_moderator_form);

I expected to see this happen: No clippy warnings.

Instead, this happened:

error: this expression borrows a reference (`&deadpool_diesel::connection::Connection<diesel::pg::connection::PgConnection>`) that is immed
iately dereferenced by the compiler
   --> crates/api_crud/src/user/create.rs:195:43
    |
195 |       let join = CommunityModerator::join(&&context.pool.get().await?, &community_moderator_form);
    |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `&&context.pool.get().await?`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Its suggesting a fix that's the same as the error

Meta
  • cargo clippy -V: clippy 0.1.56 (ae90dcf 2021-08-09)
  • rustc -Vv:
rustc 1.56.0-nightly (ae90dcf02 2021-08-09)
binary: rustc
commit-hash: ae90dcf0207c57c3034f00b07048d63f8b2363c8
commit-date: 2021-08-09
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1

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.

Research direction

Start by reproducing the report with the expression in crates/api_crud/src/user/create.rs and the reported Rust nightly and Clippy versions. Inspect the needless_borrow lint's diagnostic output and verify that the suggested replacement differs from the original source; done means the warning suggests an actually different valid fix or no longer reports this case incorrectly.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.