- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onCall for participation: This a hard problem and requires more experience or effort to work onI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Summary
clone_on_copy checks if a type implements copy disregarding the lifetimes, causing it to fail in certain cases
From what I could see this problem is not only related to clone_on_copy, but to every lint that uses the is_copy function, since it doesn't take into account regions. It also seems to be related to #15577
I'm not sure if there's any reason to not consider lifetimes when checking trait implementations, but if it's a decision across clippy it may affect more lints.
Lint Name
clone_on_copy
Reproducer
I tried this code:
#![no_main]
struct Weird<'a>(&'a i32);
impl Clone for Weird<'_> {
    fn clone(&self) -> Self {
        Weird(self.0)
    }
}
impl Copy for Weird<'static> {}
impl Weird<'_> {
    fn foo(&self) -> Self {
        self.clone()
    }
}I saw this happen:
warning: using `clone` on type `Weird<'_>` which implements the `Copy` trait
  --> test3.rs:15:9
   |
15 |         self.clone()
   |         ^^^^^^^^^^^^ help: try dereferencing it: `*self`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
   = note: `#[warn(clippy::clone_on_copy)]` on by default
After applying the fixes compilation fails:
error: lifetime may not live long enough
  --> test3.rs:15:9
   |
14 |     fn foo(&self) -> Self {
   |            ----- has type `&Weird<'1>`
15 |         *self
   |         ^^^^^ copying this value requires that `'1` must outlive `'static`
error: aborting due to 1 previous error
I expected to see this happen:
No lint
Version
rustc 1.91.0-nightly (6ba0ce409 2025-08-21)
binary: rustc
commit-hash: 6ba0ce40941eee1ca02e9ba49c791ada5158747a
commit-date: 2025-08-21
host: aarch64-apple-darwin
release: 1.91.0-nightly
LLVM version: 21.1.0
Additional Labels
@rustbot label +I-suggestion-causes-error
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onCall for participation: This a hard problem and requires more experience or effort to work onI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied