Skip to content

VSCode (?) : Incomplete clippy suggestions results in RA deleting code #12069

Closed
@Crzyrndm

Description

@Crzyrndm

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)

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)
image
clippy correctly identifies this as an opportunity to suggest a while-let loop
image
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
image
And now any code that was in the body of the if is gone
image

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions