RS.CLIPPY.NEEDLESS_BORROW

Taking a reference that is going to be automatically dereferenced

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: needless_borrow. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for address of operations (&) that are going to be dereferenced immediately by the compiler.

Why is this bad?

Suggests that the receiver of the expression borrows the expression.

Known problems

The lint cannot tell when the implementation of a trait for &T and T do different things. Removing a borrow in such a case can change the semantics of the code.

Example

fn fun(_a: &i32) {}

let x: &i32 = &&&&&&5;
fun(&x);

Use instead:

let x: &i32 = &5;
fun(x);

Past names

  • ref_in_deref

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)