-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Lint against calling .clone() on an otherwise copyable value. #27266
Comments
Is it really necessary? Doesn’t sound like a footgun type of an issue. |
I agree with @nagisa, especially if your code is generated (macros, syntax extensions, etc...). |
I don't know how else to clean up the compiler code. In a cargo crate I'd just use clippy. |
@eddyb ...is it a serious problem? |
Since new lints have a big impact on users of rustc, the policy is that they should go through the RFC process like other user-facing changes. As such, I'm going to give this one a close, but if anyone comes across this ticket and wants this lint, consider adding it to clippy and/or writing up an RFC. Thanks! |
@steveklabnik That's fine, I'm hoping #31123 will let us use clippy on rustc fairly easy. |
(Exists in clippy, https://github.com/Manishearth/rust-clippy/wiki#clone_on_copy) |
This seems really useful in normal rust, like with <&T>::clone |
The current policy is no new lints in Rust unless it's really special. |
Merp :( |
Certain types could start out as having contents that move and then switch to only copyable field, or could just be missing
#[deriving(Copy)]
initially.If
Copy
is implemented after that type has been used in a large codebase (there's a few cases inrustc
itself), there will likely be many.clone()
calls around, and finding which ones belong to the type could be tedious.A lint would ease this work, by suggesting the replacement of an unnecessary
x.clone()
call with a dereference (ifx
is a reference to the type being cloned - could use the autoderef count here) or nothing at all (since using aCopy
lvalue as an rvalue will just copy it).The text was updated successfully, but these errors were encountered: