Description
Rust analyser version: 0.2.1022 (current stable)
VSCode version: 1.66.2 (current stable)
"rust-analyzer.checkOnSave.command": "clippy"
NOTE: I'm not sure whether this is RA or clippy or somewhere in between. Starting here as cargo clippy --fix
does the right thing (no auto-fix applied)
- After writing this up I decided that the clippy output was decidedly unhelpful so opened an issue there as well: Incomplete suggestion combines poorly with other tools (rust-analyzer) rust-clippy#8739
A number of clippy replacements are incomplete. They provide a template for the suggested output, but direct copy paste will not give equivalent/improved behaviour. Some sections are left to the user to fill in
A simple example is the clippy::while_let_loop
lint (I feel like it's not the only one, but perhaps I just keep running into the same issue)
clippy correctly identifies this as an opportunity to suggest a while-let loop
Note that the internals of the loop is left to the the user in the suggested replacement. This is where things become problematic
RA picks up the suggested replacement
And now any code that was in the body of the if is gone
Honestly, I think the clippy output is at best highly unhelpful here. There doesn't seem to be a good reason for the output not to include the body of the pre-transform if. RA on the other hand is perhaps just a little too trusting of what it is being told. Regardless, as a user, the result is rather unpleasant and the suggestion can easily be read as running out of space (and displaying a compressed form in the UI) so what comes out is unexpected (at least the first time it is encountered anyway)