RS.CLIPPY.NON_CANONICAL_CLONE_IMPL
Non-canonical implementation of `Clone` on a `Copy` type
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: non_canonical_clone_impl. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for non-canonical implementations of Clone when Copy is already implemented.
Why is this bad?
If both Clone and Copy are implemented, they must agree. This can done by dereferencing
self in Clone's implementation, which will avoid any possibility of the implementations
becoming out of sync.
Example
#[derive(Eq, PartialEq)]
struct A(u32);
impl Clone for A {
fn clone(&self) -> Self {
Self(self.0)
}
}
impl Copy for A {}
Use instead:
#[derive(Eq, PartialEq)]
struct A(u32);
impl Clone for A {
fn clone(&self) -> Self {
*self
}
}
impl Copy for A {}
Past names
- incorrect_clone_impl_on_copy_type