Skip to content

Overly verbose suggestion display for trailing whitespace changes #140750

Open
@Jarcho

Description

@Jarcho

When a suggestion removes a line the diff suggests removing and re-adding the previous line. We do these kinds of suggestions a fair bit in clippy to make --fix actually remove the line.

e.g. in needless_return the code:

fn main() {
    if true {
        println!("foo");
        return;
    } else {
        println!("bar");
    }
}

Gives the suggestion:

 --> src/main.rs:3:25
  |
3 |           println!("foo");
  |  _________________________^
4 | |         return;
  | |______________^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
  = note: `#[warn(clippy::needless_return)]` on by default
help: remove `return`
  |
3 -         println!("foo");
4 -         return;
3 +         println!("foo");
  |

This suggests to remove and re-add println!("foo"); rather than just remove the return line. The lint span spanning multiple lines is entirely on clippy, but the suggestion display can't be fixed by us.

cc rust-lang/rust-clippy#14750

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-diagnostic-infraDiagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions