RS.CLIPPY.BORROW_DEREF_REF

Deref on an immutable reference returns the same type as itself

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

What it does

Checks for &*(&T).

Why is this bad?

Dereferencing and then borrowing a reference value has no effect in most cases.

Known problems

False negative on such code:

let x = &12;
let addr_x = &x as *const _ as usize;
let addr_y = &&*x as *const _ as usize; // assert ok now, and lint triggered.
                                        // But if we fix it, assert will fail.
assert_ne!(addr_x, addr_y);

Example

let s = &String::new();

let a: &String = &* s;

Use instead:

let a: &String = s;