diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-07-03 21:03:37 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2024-07-04 05:04:48 +0000 |
| commit | a06a18a47fc36b6c2c7c317c7611fe0a2960765b (patch) | |
| tree | 7f3b88849b38a10d2b6c096aa4e33ecfa4a76113 /compiler/rustc_errors/src | |
| parent | 9344779f718e847283a1ada901bad1222bd5d55b (diff) | |
| download | rust-a06a18a47fc36b6c2c7c317c7611fe0a2960765b.tar.gz rust-a06a18a47fc36b6c2c7c317c7611fe0a2960765b.zip | |
Properly handle removal suggestion rendering
Do not leave a `+ ` line with only whitespace. In reality, the user will want to remove the entire line.
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 45118bcc58a..aa47ca16676 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2273,9 +2273,26 @@ impl HumanEmitter { &normalize_whitespace(last_line), Style::NoStyle, ); - buffer.puts(*row_num, 0, &self.maybe_anonymized(line_num), Style::LineNumber); - buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition); - buffer.append(*row_num, &normalize_whitespace(line_to_add), Style::NoStyle); + if !line_to_add.trim().is_empty() { + // Check if after the removal, the line is left with only whitespace. If so, we + // will not show an "addition" line, as removing the whole line is what the user + // would really want. + // For example, for the following: + // | + // 2 - .await + // 2 + (note the left over whitepsace) + // | + // We really want + // | + // 2 - .await + // | + // *row_num -= 1; + buffer.puts(*row_num, 0, &self.maybe_anonymized(line_num), Style::LineNumber); + buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition); + buffer.append(*row_num, &normalize_whitespace(line_to_add), Style::NoStyle); + } else { + *row_num -= 1; + } } else { *row_num -= 2; } |
