cargo: `cargo fix`: Improve handling of MaybeIncorrect suggestions
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 https://github.com/rust-lang/cargo/issues/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.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 8
- Comments: 42 (35 by maintainers)
This exists today as
__CARGO_FIX_YOLO=1. It would be great to make that more discoverable with a CLI option.All the kids are saying it
@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.
That also sounds reasonable to me. (Edit: no pun intended)
Especially this reason could be used in such a pick and choose prompt.
In Clippy
MaybeIncorrectis used interchangeable for both cases. Sometimes we use it, if the suggestion might result in new errors (e.g. the borrow checker might complain or an additional (trait) import is needed). And sometimes, because it’s a semantic change (e.g. removes a possibly panicking expression). At least, that’s how I use it and recommend it in reviews.So maybe splitting it up in
MayIntroduceNewErrorandSemanticChange(with possibly better names) would make sense.The idea behind splitting is that
MayNotCompilesuggestions may compile, and guarantee not to change behavior if they do. So a tool like rust fix could apply them, check compiling the result and roll them back on failure. On the other handMayChangeBehaviorhave no such guarantee.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
rustfixdoes so it’s all user-driven anyway.It also means that the user workflow can be “run rustfix with
PotentialCompileError, and then manually fix any errors they see”.Whereas for
PotentialBehaviorChangethe workflow will probably be to review them one by one, and ideally put them in a separate commit for cleaner review (as a reviewer I’d want the direct rustfix fixes in one commit,PotentialCompileErrorfixups in another, andPotentialBehaviorChangeones in a third)Yeah, having that split makes sense to me. Migration is going to be annoying though.
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 😅
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.
That’s
Unspecified, no?https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/enum.Applicability.html
As a clippy user I would also be interested in a better handling of
MaybeIncorrectoptions.clippy::semicolon_if_nothing_returnedis the canonical example of the lint that if failing sometimes automatically is not an issue, and on a large codebase it’s much easier to dealt with only the corner cases manually than all the occurrences.The split of
MaybeIncorrectis probably worth being nominated in a clippy meeting?I also agree with splitting
MaybeIncorrect. PerhapsMayFailToCompile,MayChangeBehaviorandMayBeCounterproductive(for things that might compile and keep behavior, but not help readability or perf).Proabably “you only live once”, which is
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