-
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
incorrect_clone_impl_on_copy_type false positive on empty enum #11071
Comments
Can you elaborate why an enum like this isn't just using derives? #[derive(Copy, Clone)]
enum Void {} |
We could probably ignore I suppose it does changing the meaning of the code ( |
It can. In fact this is exactly the impl that the standard derive generates (as of rust-lang/rust#113770 anyway). #[derive(Clone)]
enum Void {} #[automatically_derived]
impl ::core::clone::Clone for Void {
#[inline]
fn clone(&self) -> Void { match *self {} }
} As an author of derive macros, handwriting the code I'm going to want it to generate is pretty much always the first step. Depending on the macro, I even run Clippy on my handwritten impl to catch anything silly up front before starting to implement the macro. I think there is room for a warn-by-default lint for the purpose of saying "did you know you can delete this handwritten impl and just use derive?" (more broadly than just for Clone) but this issue is in regard to a deny-by-default lint that says "the code in this impl is incorrect", which is a false positive for this particular lint because the code is correct and identical to what the standard library |
Hmm, I don't know what the clippy guidance for levels is. In rustc this would definitely not pass the deny-by-default bar, but maybe it's expected that clippy is more picky here? I suppose one option would be to have two lints:
|
deny-by-default lints are pretty rare in rustc, and for good reason, you don't want something slightly pedantic (like I agree with what you said on two lints, I think a lint for saying "this could be derived" would be nice |
Summary
Would you be willing to consider the exact expression
match *self {}
a correct Clone impl for a Copy type?This immediately conveys "don't even bother" in a way that
*self
does not.Lint Name
incorrect_clone_impl_on_copy_type
Reproducer
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: