-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable expl_impl_clone_on_copy
when Copy
is manually implemented.
#1254
Comments
Just adding a clarification here: for generics, the deriving infrastructure will add bounds for all generic parameters, even when they aren't needed. In those situations a manual implementation is necessary to avoid those bounds, in which situation it would be nice for the warning to be automatically suppressed. Example: #![allow(unused)]
use std::marker::PhantomData;
struct Marker<A>(PhantomData<A>);
// Can copy/clone `Marker` regardless of what `A` is
impl<A> Copy for Marker<A> {}
impl<A> Clone for Marker<A> {
fn clone(&self) -> Self {
*self
}
}
struct NoClone;
fn main() {
let m: Marker<NoClone> = Marker(PhantomData);
let m2 = m.clone();
} Following clippy's suggestion here to auto derive either/both of |
This seems me like an inconsistent use of Maybe I'm completely off with my reasoning here... I never fully understood all |
@oli-obk this example looks ok. pub struct Iter<'a, T: 'a> {
ptr: *const T,
end: *const T,
_marker: marker::PhantomData<&'a T>,
} Without the marker, the iterator would not depend on |
That's not true (anymore), otherwise http://play.integer32.com/?gist=f7d889a3a96894cea5f855488f9a94d5&version=stable wouldn't build. There used to be some issues around these derives, but I think most have been solved. |
Maybe derives know about reference fields now, but they still don't know about any |
They don't need to know anything about #[derive(Copy, Clone)]
struct Foo<'a, T: 'a>(std::marker::PhantomData<&'a T>);
#[derive(Copy, Clone)]
struct Bar<'a, T: 'a>(Foo<'a, T>); works just fine. |
@oli-obk I'm using the phantom data to cheat around unused parameters for a builder what will convert
According to the output of rustdoc the bound is As a second data point, this example will fail to compile even though
|
I found rust-lang/rust#26925, so it looks like this issue is going to stay with us. |
In one of my projects, I have several cases like this: pub struct Foo(Option<unsafe extern "system" fn()>);
impl Copy for Foo {}
impl Clone for Foo {
fn clone(&self) -> Self {
*self
}
} Unfortunately, At the moment, I simply disable |
As long as this is not fixed, it should be listed as a known problem with the lint. Currently, known problems are "None": https://rust-lang-nursery.github.io/rust-clippy/v0.0.165/index.html#expl_impl_clone_on_copy |
Improve `expl_impl_clone_on_copy` fixes: #1254 changelog: Check to see if the generic constraints are the same as if using derive for `expl_impl_clone_on_copy`
Due to some limitations in the deriving infrastructure, it's sometimes necessary to explicitly implement
Copy
andClone
. In these cases, it would be nice if clippy detected the explicitCopy
implementation and didn't warn about the explicitClone
implementation.The text was updated successfully, but these errors were encountered: