Skip to content

clone_on_copy does not trigger in some cases if the cloned value is borrowed directly after #16969

@antonilol

Description

@antonilol

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions