-
Notifications
You must be signed in to change notification settings - Fork 2k
False positive for expl_impl_clone_on_copy when Copy is conditionally implemented #16816
Copy link
Copy link
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Type
Fields
Give feedbackNo fields configured for issues without a type.