RS.CLIPPY.CLONE_ON_REF_PTR
Using `clone` on a ref-counted pointer
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: clone_on_ref_ptr. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for usage of .clone() on a ref-counted pointer,
(Rc, Arc, rc::Weak, or sync::Weak), and suggests calling Clone via unified
function syntax instead (e.g., Rc::clone(foo)).
Why restrict this?
Calling .clone() on an Rc, Arc, or Weak
can obscure the fact that only the pointer is being cloned, not the underlying
data.
Example
let x = Rc::new(1);
x.clone();
Use instead:
Rc::clone(&x);