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

Make clone_on_copy lint machine applicable #4826

Closed
jyn514 opened this issue Nov 18, 2019 · 3 comments · Fixed by #5745
Closed

Make clone_on_copy lint machine applicable #4826

jyn514 opened this issue Nov 18, 2019 · 3 comments · Fixed by #5745
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@jyn514
Copy link
Member

jyn514 commented Nov 18, 2019

Copy/pasted from rust-lang/rustfix#182:

This gives a warning instead of replacing it with the suggested code:

$ cargo +nightly fix -Z unstable-options --clippy
warning: using `clone` on a `Copy` type
   --> src/parse/mod.rs:258:27
    |
258 |                 location: self.next_location().clone(),
    |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*self.next_location()`

It would be really nice to have this be done automatically, since I currently have about 20 of these warnings in my code.

$ cargo +nightly --version
cargo 1.40.0-nightly (5da4b4d47 2019-10-28)
$ cargo +nightly clippy -V
clippy 0.0.212 (b4f17697 2019-11-14)
@jyn514
Copy link
Member Author

jyn514 commented Nov 18, 2019

cc @Manishearth

@Manishearth Manishearth changed the title Make more lints machine applicable: Make clone_on_copy lint machine applicable: Nov 18, 2019
@Manishearth Manishearth changed the title Make clone_on_copy lint machine applicable: Make clone_on_copy lint machine applicable Nov 18, 2019
@flip1995
Copy link
Member

In theory the suggestion is already fixable by rustfix:

span_lint_and_then(cx, CLONE_ON_COPY, expr.span, "using `clone` on a `Copy` type", |db| {
if let Some((text, snip)) = snip {
db.span_suggestion(expr.span, text, snip, Applicability::Unspecified);
}
});

Only thing left to do here is to figure out the applicability level. (And maybe pass it through the snippet_with_applicability function)

@flip1995 flip1995 added L-suggestion Lint: Improving, adding or fixing lint suggestions C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Nov 18, 2019
@Manishearth
Copy link
Member

Manishearth commented Nov 18, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants