cargo: Output which errors are automatically correctable, to improve discoverability of `cargo fix` and `cargo clippy --fix`
Problem
cargo fix and cargo clippy --fix can be great tools for sparing developer cycles, especially when a new version of cargo is released. However, the discoverability of these tools is a problem: not everyone knows they exist.
Proposed Solution
To improve discoverability, we could do something similar to what rubocop does: each error could include info about whether it’s automatically correctable or not. This may prompt users who don’t know about this feature to go find it. It also helps users who do know about the feature: they can avoid running the fix command in situations where it’ll be useless because the tool actually can’t automatically fix those particular errors.
For reference, here’s a screenshot of rubocop’s output:

Notes
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 25 (24 by maintainers)
Commits related to this issue
- Auto merge of #10989 - Muscraft:add-auto-fix-note, r=weihanglo add a note that some warnings (and/or errors) can be auto-fixed This adds a note that some warnings (and/or errors) can be auto-fixed b... — committed to rust-lang/cargo by bors 2 years ago
- Auto merge of #11399 - Muscraft:autofix-for-clippy, r=weihanglo fix: Make auto-fix note work with `clippy` [Someone pointed out](https://github.com/rust-lang/cargo/issues/10976#issuecomment-13075381... — committed to rust-lang/cargo by bors 2 years ago
- Auto merge of #11558 - Muscraft:stabilize-cargo-fix-message, r=epage feat: stabilize auto fix note A note that some warnings could be fixed by running a `cargo fix` command was added in #10989 and m... — committed to rust-lang/cargo by bors a year ago
This seems interesting, I’d love to work on it if we can figure out what the message should be. I lean towards an explicit callout to
cargo --fixbut I could see just having how many are fixable.It was discussed in a recent cargo team meeting to move forward with showing a message that
cargo fixcan fix some warnings but only on nightly.Current format:
Current implementation from #10989:
nightlyonly to allow iterative (potentially breaking) updates driven by get user feedbackcargo fixand errorsOpen questions:
How I have it currently working doesn’t work for clippy as its a subcommand
I was thinking to keep things more targeted
helpthough it could be added, so I’ve been usingnote:for similar.On a related note, I’ve been meaning to bring up if cargo should align with rustc in its error style guide
Running
cargo clippywill also emit this message, but as it’s suggesting a plaincargo fixit won’t apply the suggestionsIt would be great it if could suggest running
cargo clippy --fix, but if a way to do that hasn’t been decided yet it’s probably best to omit the message when eitherRUSTC_WRAPPERorRUSTC_WORKSPACE_WRAPPERare set@ehuss I want to contrast this with me who nevers use
cargo fixbecause it never crosses my mind. Even if I did, I probably wouldn’t want to do the mental calculus to see if its worth running. Adding this would be a big help to me and, I suspect, to a lot of new users.As for balancing noise vs help, we intentionally made it so we only emit 1 brief line for the entire run because of this. I personally suspect this one line won’t be an issue
Maybe we should limit the message to only when there are fixable
errorswarnings?To me, this just means we evaluate the behavior between
cargo fixandcargo fix --allow-dirtyto see which holistic solution is better for being the default recommended command.I think a
--allow-dirtyflag, whether we suggest it or not, will give users enough of a hint about this. Also, by having increased visibility of the feature, we’ll likely get more bug reports so we’ll improve the behavior.ditto about this just being an opportunity to improve it.
As a user, I don’t care. I’ll run the command and get things fixed and then address the rest. I’ll be elated to not have to manually update 200+ warnings that I sometimes get.
I at least do not use
rust-analyzerand punting to rust-analyzer is a slipper slope (we don’t needcargo addbecauserust-analyzershould do it, etc).Seems reasonable. I can’t remember which order the compiler does it but I’m assuming errors would go before warnings.
maybe something like this?
and only display the
helpmessage if there’s at least one automatically fixable warning.Oh, great! I had missed the intent of your previous message
Another approach is the one I took in
cargo upgrade. I report the status of every dependency but if a dependency is held back and needs a flag to be upgraded, I track that and report it at the end.In this case, it’d be a note like
EDIT: The challenge with this is it violates layering / separation of concerns. cargo doesn’t know about these messages to put the suggestion in and the commands don’t know about cargo to do so.
@jyn514 yes, rather than tagging every command that can output warnings, I just tagged the ones that the suggestions would be for.