Skip to content

False positive for expl_impl_clone_on_copy when Copy is conditionally implemented #16816

@MonterraByte

Description

@MonterraByte

Summary

expl_impl_clone_on_copy is emitted incorrectly for structs that aren't necessarily Copy, when Copy is implemented conditionally.

Lint Name

expl_impl_clone_on_copy

Reproducer

I tried this code:

pub struct A<T>(T);

impl<T: Copy> Copy for A<T> {}

impl<T: Clone> Clone for A<T> {
    fn clone(&self) -> Self {
        Self(self.0.clone())
    }
}

I saw this happen:

warning: you are implementing `Clone` explicitly on a `Copy` type
 --> src/lib.rs:5:1
  |
5 | / impl<T: Clone> Clone for A<T> {
6 | |     fn clone(&self) -> Self {
7 | |         Self(self.0.clone())
8 | |     }
9 | | }
  | |_^
  |
  = help: consider deriving `Clone` or removing `Copy`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#expl_impl_clone_on_copy
  = note: `-W clippy::expl-impl-clone-on-copy` implied by `-W clippy::pedantic`
  = help: to override `-W clippy::pedantic` add `#[allow(clippy::expl_impl_clone_on_copy)]`

I expected to see this happen:

No warnings, as there's no T: Copy bound for that impl.

Version

clippy 0.1.96 (e0e95a7187 2026-04-04)

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

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