-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
cargo fix
: Improve handling of MaybeIncorrect suggestions
#13028
Comments
cc @estebank |
also cc @ehuss for thinking about what the UX would be like from cargo's perspective |
Is there something on the |
@estebank no, I don't think that'll help. MaybeIncorrect already is that variant: there's another one for when you're absolutely sure it's incorrect. MaybeIncorrect is just when it's a bad idea to auto apply the fix without checking; because the fix may introduce semantic change (etc) At least the way it's used in clippy, most MaybeIncorrects are not supposed to be blindly applied. cc @rust-lang/clippy in case folks have opinions on whether we need additional suggestion applicability types This should be entirely on the rustfix/cargo side I think. |
I think to some extent rustfix already tries to skip applying lint results where the resulting code does not compile. |
The problem is that MaybeIncorrect is often not stuff that is incorrect because it won't compile, it's incorrect because it changed the semantics of the program in a way clippy thinks is according to intention but might not be |
In Clippy So maybe splitting it up in |
Both reasons might apply. That may be reason enough not to split it. Unless we say, "if it is maybe incorrect for multiple reasons, prefer X." Is the motivation for splitting to offer an explanation to the user? Maybe instead we could add a "incorrect reason" field. In fact, in reviews I've picked up the habit of making sure there is a code comment explaining |
That also sounds reasonable to me. (Edit: no pun intended)
Especially this reason could be used in such a pick and choose prompt.
|
For what it's worth, I think "may introduce error" can also be described as "maybe incomplete" - additional changes are necessary to "complete" the intended suggestion, like adding an import. |
This exists today as |
@jyn514 what does the YOLO stand for ? |
I think it tries to apply suggestions no matter what...? Line 581 in 50a0af4
|
Proabably “you only live once”, which is
|
All the kids are saying it |
@NikosEfthias sample usage:
|
@estebank @rust-lang/clippy it's been a while since it's been filed and there's some interest in exposing applicability levels to users. Before we do so, do y'all think it's worth splitting MaybeIncorrect into SemanticChange and MayIntroduceNewError? Ideally the applicability exposition lets you choose how far you want to go. |
I think it does make sense to split that. In Clippy, we use this level for both of those use cases interchangeably. EDIT: Wait, I suggested that above. I couldn't remember that I did that 😅
|
Maybe we can do a nice audit to clippy to see which goes where. I wonder if that's something @3tilley is interested in looking in to The way I see it is that there are three somewhat independent work items here:
|
Yeah, having that split makes sense to me. Migration is going to be annoying though. |
I also agree with splitting |
How does splitting applicability improve UX? Or what problem does it solve? |
We may use the split values for reporting. Users would likely be interested what they should expect. Also if we had a "might not compile, but if it does, it's OK" category, rustfix could try to auto-fix and back out on errors. |
@camsteffen It lets users set some minimum applicability level with rustfix, instead of going with the default. The way I see it, the applicabilities go in order of least to most applicable:
For example, quite often with the latter two I'm actually comfortable running rustfix on my codebase, with the former two I kinda want to review them case by case. |
As a clippy user I would also be interested in a better handling of The split of |
Just chiming in, being able to say something like |
This would also be useful for rustc tests. It's not always the case that a |
@est31 compiletest applies all suggestions regardless of applicability with the |
@ehuss oh it seems compiletest seems to use |
Here's the current plan:
@Veykril does this look OK to you from a rust-analyzer perspective? are these categories useful? |
I'm not sure I understand "remove MachineApplicable". Isn't that the variant that is most useful? Did you maybe mean MaybeIncorrect? Can you define exactly what these two categories mean? |
Er, sorry, meant MaybeIncorrect
It's an interesting point about suggestions that are outright buggy. Perhaps we should add a Nursery/Buggy category? Not sure. I kinda feel BehaviorChange covers that okayishly. Right now, MaybeIncorrect covers a lot of different types of incorrectness with lots of different implications on how people use the tooling. I'm not sure if Buggy and PotentialBehaviorChange have different implications on tooling use |
We might want to have an explicit |
That's https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/enum.Applicability.html |
I don't think rust-analyzer cares too much about this, I can't think of a direct use case for us here aside from maybe grouping quickfixes of these two kinds differently (r-a is doing a terrible job at categorizing quick fixes currently), as for both we'd want to show the user a quickfix in the UI (as we do with |
@jyn514 it could be, I'm not sure if we are using it that way though. |
I think Unspecified was for diagnostics that have not been vetted as to whether or not they work correctly. I believe that was used when the applicability system was put in, and there was a huge list of diagnostics to update, so Unspecified was the default until a more appropriate category could be determined. |
The idea behind splitting is that Changing the names will help us keep track of which suggestions have been vetted. |
Yeah I guess that r-a isn't batching things the way
It also means that the user workflow can be "run rustfix with Whereas for |
That said, I don't think a |
cc @Muscraft |
cargo fix
: Improve handling of MaybeIncorrect suggestions
Thanks a lot @jyn514 this is incredibly helpful! In my case, I need to rename struct fields from So I think for cases like this it's not really "YOLO" and it'd be nice to expose it to users more cleanly but even having it at all is already a huge deal. |
When the compiler or clippy produce suggestions, some of them are marked as MaybeIncorrect; i.e. the suggestion should probably not be automatically applied. rustfix currently doesn't touch these.
This leads to confusion like in #8806, and is somewhat frustrating. We should at the very least be clear that such suggestions were not applied.
Ideally, we should provide a mode where you can apply them anyway (
cargo clippy --fix --apply-all-suggestions
?), or apply them using a "pick and choose" mode. We can then mention it when people have suggestions that were not applied.See also: #13023
The text was updated successfully, but these errors were encountered: