Skip to content

clone_on_ref_ptr adds an unnecessary & #15741

@ada4a

Description

@ada4a

Summary

The lint turns rc.clone() into Rc::clone(&rc), even if rc is already a reference. That in turn causes clippy::needless_borrow to fire.

Reproducer

I tried this code:

#![allow(unused)]
#![warn(clippy::clone_on_ref_ptr)]

use std::rc::Rc;

fn foo(rc: &Rc<str>) {
    rc.clone();
}

I expected to see this happen:

 --> src/lib.rs:7:5
  |
7 |     rc.clone();
  |     ^^^^^^^^^^ help: try: `Rc::<str>::clone(rc)`
  |

Instead, this happened:

warning: using `.clone()` on a ref-counted pointer
 --> src/lib.rs:7:5
  |
7 |     rc.clone();
  |     ^^^^^^^^^^ help: try: `Rc::<str>::clone(&rc)`
  |

Version

rustc 1.92.0-nightly (f6092f224 2025-09-22)
binary: rustc
commit-hash: f6092f224d2b1774b31033f12d0bee626943b02f
commit-date: 2025-09-22
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.1

Additional Labels

@rustbot label -C-bug +C-enhancement

@rustbot claim

Metadata

Metadata

Assignees

Labels

C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions