cargo fix --clippy isn't as smart as I want it to be :(
jyn514 opened this issue · 3 comments
jyn514 commented
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)
ehuss commented
Thanks for the report. I think there are two things here:
- The
clone_on_copy
lint has an Applicability ofUnspecified
.cargo fix
will only applyMachineApplicable
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 (rust-lang/rust-clippy#1472) where it gives false positives. - A workaround would be rust-lang/cargo#13023, where an opt-in could be added to try non-machine-applicable suggestions.
jyn514 commented
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 commented
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.