diff options
| author | Badel2 <2badel2@gmail.com> | 2023-05-19 00:44:14 +0200 |
|---|---|---|
| committer | Badel2 <2badel2@gmail.com> | 2023-05-19 20:58:06 +0200 |
| commit | cbb41008fd43b512ffdbd35cebee2e4518b2181e (patch) | |
| tree | be9a0219f072c1d5ab0480dcf7b7e34c18424b94 /compiler/rustc_errors/src/emitter.rs | |
| parent | 8a281f9c796ee8cbebb07bbeec04ef2f2dd8db45 (diff) | |
| download | rust-cbb41008fd43b512ffdbd35cebee2e4518b2181e.tar.gz rust-cbb41008fd43b512ffdbd35cebee2e4518b2181e.zip | |
Fix overflow in error emitter
Diffstat (limited to 'compiler/rustc_errors/src/emitter.rs')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 68e57de5e08..3e38d6afb0b 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2303,22 +2303,25 @@ impl EmitterWriter { // Colorize addition/replacements with green. for &SubstitutionHighlight { start, end } in highlight_parts { - // Account for tabs when highlighting (#87972). - let tabs: usize = line_to_add - .chars() - .take(start) - .map(|ch| match ch { - '\t' => 3, - _ => 0, - }) - .sum(); - buffer.set_style_range( - *row_num, - max_line_num_len + 3 + start + tabs, - max_line_num_len + 3 + end + tabs, - Style::Addition, - true, - ); + // This is a no-op for empty ranges + if start != end { + // Account for tabs when highlighting (#87972). + let tabs: usize = line_to_add + .chars() + .take(start) + .map(|ch| match ch { + '\t' => 3, + _ => 0, + }) + .sum(); + buffer.set_style_range( + *row_num, + max_line_num_len + 3 + start + tabs, + max_line_num_len + 3 + end + tabs, + Style::Addition, + true, + ); + } } *row_num += 1; } |
