Cargo clippy fix doesnt fix anything

For some reason cargo clippy --fix doesnt fix anything just reports the warnings. Is this a known bug or something ?

Only certain clippy warnings come with automatically applicable fixes, AFAIK. Perhaps your concrete code you tested this on only generated warnings without support for automatic fixing via cargo clippy --fix?

I am aware of that however somehow vscode can fix those warnings using clippy but clippy itself cannot fix using --fix

What kind of lints are we talking about? Mind sharing a warning message or at least the name of one of the lints that you can fix in vscode but not with the cargo clippy --fix invocation?

If you look up a lint here: Clippy Lints, you can find “Applicability” information; I belive only those described as “MachineApplicable” are applied automatically.

What vscode extensions do you use? I’m just guessing, but maybe those can apply more kinds of suggestions; in particular those that are only marked as “MaybeIncorrect”? It would make sense to support those for manual case-by-case application in vscode, but not for batch-application on the CLI, because if you review every case manually, you can catch cases where the suggestion would’ve been incorrect.

mainly replacing ok_or's with or_or_else's
I am refactoring an old project and its a nightmare

Structured suggestions are marked with a "level of confidence". It might be that these lints you are seeing are marked as Unknown, HasPlaceholders or MaybeIncorrect.

If that’s clippy::or_fun_call, that one is (for some reason) marked as “HasPlaceholders”.

I’m not quite understanding what kind of placeholders we are talking about; the suggestion seems fine to me? But in any case it might still legitimately not fall into MachineApplicable, because it changes semantics.

Just found an issue about this and apparently you might even be able to use the solution described there:

Ideally, we should provide a mode where you can apply them anyway (cargo clippy --fix --apply-all-suggestions?),

This exists today as __CARGO_FIX_YOLO=1 . It would be great to make that more discoverable with a CLI option.

Edit: Tested it, something like

__CARGO_FIX_YOLO=1 cargo clippy --fix

appears to apply suggestions from clippy::or_fun_call successfully.

oh thats amazing let me try that

yep it works beautifully

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.