-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Output which errors are automatically correctable, to improve discoverability of cargo fix
and cargo clippy --fix
#10976
Comments
cargo fix
and cargo clippy --fix
by outputting which errors are automatically correctablecargo fix
and cargo clippy --fix
This information is already available in the JSON output: // foo.rs
#[derive(Debug(x))]
struct Foo;
|
@epage this isn't unique to clippy, it's useful for normal |
@jyn514 yes, rather than tagging every command that can output warnings, I just tagged the ones that the suggestions would be for. |
Another approach is the one I took in 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. |
I don't understand the problem? Cargo already knows about these suggestions because they're present in the JSON output from rustc. Cargo already parses those messages to know how many errors were present. |
Here's an example of a similar change in the past: #9655 |
Oh, great! I had missed the intent of your previous message |
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 |
maybe something like this?
and only display the |
I was thinking to keep things more targeted
On a related note, I've been meaning to bring up if cargo should align with rustc in its error style guide |
@epage what do you think should happen for errors that can be fixed automatically? maybe something like this?
|
Seems reasonable. I can't remember which order the compiler does it but I'm assuming errors would go before warnings. |
Some things for us to keep in mind, depending on what layer this is put in at
|
Oh right, clippy is external. Instead, we'll want to create a separate issue in its repo: https://github.com/rust-lang/rust-clippy/issues |
@epage hmm, I've forgotten how the cargo-clippy wrapper works under the hood - does it call cargo? I wonder if making this work for I think it uses RUSTC_WORKSPACE_WRAPPER? |
How I have it currently working doesn't work for clippy as its a subcommand |
|
@ehuss I want to contrast this with me who nevers use 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
To me, this just means we evaluate the behavior between
I think a
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 |
For a single error message, an additional line can increase the amount of output by 10%. An individual addition like this isn't likely to be "too verbose" on its own, but the aggregate of all notes, hints, descriptions can eventually get to the point where the user is exposed to too much information to be overwhelming. Just as a thought, would it work to extend the existing summary line, maybe something like this?
I think the only safe thing that can be done right now is to only suggest when there are 0 total errors. I think it would also need to be restricted to I'm also concerned that the suggestion of running
My concern is about the overall user experience as it would exist today. For example:
There are other concerns, like I think encouraging people to use something that does not have a good user experience should be done with caution. I don't feel like there is a need for more bug reports; there are plenty of known deficiencies with |
hmm, having the note suggest
That would be fixed by making the note slightly smarter :) suggesting
Hmm, I think this is talking about slightly different bugs from what you mentioned originally:
Those are usually bugs in the compiler emitting the lint, not rustfix itself, and my impression is that both T-clippy and T-compiler are good about fixing broken suggestions pretty quickly :) There are certainly bugs in rustfix itself, but they're predictable (not fixing rustdoc lints, multi-span suggestions, path dependencies) and we can avoid suggesting I agree that having rustfix immediately say "refusing to update files because you have changes" is not a great UX, but I do want to mention there are cases you'd want to use rustfix without making changes, for example when updating your toolchain and fixing clippy lints (which was the original motivation for @jgpaiva opening this issue). |
My impression is not the same. There are plenty of issues about bad MachineApplicable suggestions that have been open for many years. I don't consider that by itself a blocker, just that it is a contribution to the overall possibly poor user experience. |
They ran a command with the intention of fixing their source. I don't see users would then be surprised that it modified their code.
Personally, I wonder if we should make People had made the opposite suggestion in the thread for merging
People only rarely running |
It was discussed in a recent cargo team meeting to move forward with showing a message that Current format:
Current implementation from #10989:
Open questions:
|
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 by running `cargo --fix`. This only supports `cargo check` as we can't show the same note for `cargo clippy` since it is an external subcommand. The message for the note was taken from [#10976 (comment)](#10976 (comment)).
Running It would be great it if could suggest running |
fix: Make auto-fix note work with `clippy` [Someone pointed out](#10976 (comment)) that the suggestion to run `cargo --fix` did not work properly for `cargo clippy`. This makes sure the correct command to run is output when running under `cargo clippy`. This is done by checking if the `RUSTC_WORKSPACE_WRAPPER` environment variable is set, since `clippy` [sets this every run](https://github.com/rust-lang/rust-clippy/blob/51ec465cc3dfb62a2dad7e808b399fa76a1c9170/src/main.rs#L140). Since other things can use `RUSTC_WORKSPACE_WRAPPER`, we look for a wrapper named [`clippy-driver`](https://github.com/rust-lang/rust-clippy/blob/51ec465cc3dfb62a2dad7e808b399fa76a1c9170/src/main.rs#L120). Since `clippy` might not be available everywhere `cargo` is tested, this is tested using a `rustc` wrapper.
Problem
cargo fix
andcargo 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
The text was updated successfully, but these errors were encountered: