rust-lang / rust-lang/rust

Overly verbose suggestion display for trailing whitespace changes

Open
#140,750 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics C-bug D-diagnostic-infra D-verbose T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the needless_return example and inspect the compiler's suggestion-display path, using the linked rust-clippy#14750 context to understand the multi-line span. Done means the displayed suggestion removes only return instead of removing and re-adding the unchanged println!("foo"); line.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.