Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

cargo fix --clippy isn't as smart as I want it to be :( #182

Closed
jyn514 opened this issue Nov 18, 2019 · 3 comments
Closed

cargo fix --clippy isn't as smart as I want it to be :( #182

jyn514 opened this issue Nov 18, 2019 · 3 comments

Comments

@jyn514
Copy link
Member

jyn514 commented Nov 18, 2019

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)
$ ~/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/rustfmt --version
rustfmt 1.4.9-nightly (33e36670 2019-10-07)
jyn514 added a commit to jyn514/saltwater that referenced this issue Nov 18, 2019
not bothering to change any more until one of
google/rerast#31 or
rust-lang/rustfix#182 is fixed
@ehuss
Copy link
Collaborator

ehuss commented Nov 18, 2019

Thanks for the report. I think there are two things here:

  1. The clone_on_copy lint has an Applicability of Unspecified. cargo fix will only apply MachineApplicable lints. You may want to file an issue on the clippy repo to figure out why it is Unspecified. It looks like there is at least one issue (False positive for clone_on_copy when the clone is immediately borrowed rust-clippy#1472) where it gives false positives.
  2. A workaround would be cargo fix: Automatically try applying non-MachineApplicable suggestions cargo#13023, where an opt-in could be added to try non-machine-applicable suggestions.

@jyn514
Copy link
Member Author

jyn514 commented Nov 18, 2019

A workaround would be rust-lang/cargo#13023

So if I set __CARGO_FIX_YOLO then this will automatically fix everything (possible with false positives)? That's great, thanks for letting me know!

@Manishearth
Copy link
Member

Yeah, please file an issue on the Clippy repo to improve this suggestion. Clippy suggestions are largely per-case so not all of them exist yet in machine applicable form.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants