Summary
When trying to reproduce a wrong suggestion of clone_on_copy, I came across this case where it does not trigger.
Lint Name
clone_on_copy
Reproducer
I tried this code:
let mut x = 123;
let y = &x.clone();
// x might be mutated here
// y might be used is
I expected to see this happen:
clone_on_copy lint fires because a Copy type is cloned (i32).
The suggestion might not be obvious, because y is not a borrow of x, but of a clone of x. x can be explicitly copied and then borrowed using &{ x }.
Also see the wrong suggestion linked above, it has the same problem.
Instead, this happened:
No lint
Version
rustc 1.95.0 (59807616e 2026-04-14)
binary: rustc
commit-hash: 59807616e1fa2540724bfbac14d7976d7e4a3860
commit-date: 2026-04-14
host: x86_64-unknown-linux-gnu
release: 1.95.0
LLVM version: 22.1.2
Summary
When trying to reproduce a wrong suggestion of clone_on_copy, I came across this case where it does not trigger.
Lint Name
clone_on_copy
Reproducer
I tried this code:
I expected to see this happen:
clone_on_copy lint fires because a
Copytype is cloned (i32).The suggestion might not be obvious, because y is not a borrow of
x, but of a clone ofx.xcan be explicitly copied and then borrowed using&{ x }.Also see the wrong suggestion linked above, it has the same problem.
Instead, this happened:
No lint
Version