Skip to content
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

Closed
eddyb opened this issue Jul 24, 2015 · 10 comments
Closed

Lint against calling .clone() on an otherwise copyable value. #27266

eddyb opened this issue Jul 24, 2015 · 10 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@eddyb
Copy link
Member

eddyb commented Jul 24, 2015

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).

@eddyb eddyb added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Jul 24, 2015
@nagisa
Copy link
Member

nagisa commented Jul 24, 2015

Is it really necessary? Doesn’t sound like a footgun type of an issue.

@Gankra
Copy link
Contributor

Gankra commented Jul 24, 2015

I agree with @nagisa, especially if your code is generated (macros, syntax extensions, etc...).

@eddyb
Copy link
Member Author

eddyb commented 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
Copy link
Contributor

Gankra commented Jul 24, 2015

@eddyb ...is it a serious problem?

@steveklabnik
Copy link
Member

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
Copy link
Member Author

eddyb commented Feb 11, 2016

@steveklabnik That's fine, I'm hoping #31123 will let us use clippy on rustc fairly easy.

@Manishearth
Copy link
Member

@strega-nil
Copy link
Contributor

This seems really useful in normal rust, like with <&T>::clone

@Manishearth
Copy link
Member

The current policy is no new lints in Rust unless it's really special.

@strega-nil
Copy link
Contributor

Merp :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

6 participants