Fix overflow in error emitter
This commit is contained in:
parent
8a281f9c79
commit
cbb41008fd
6 changed files with 108 additions and 22 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -330,12 +330,11 @@ impl CodeSuggestion {
|
|||
});
|
||||
buf.push_str(&part.snippet);
|
||||
let cur_hi = sm.lookup_char_pos(part.span.hi());
|
||||
if cur_hi.line == cur_lo.line && !part.snippet.is_empty() {
|
||||
// Account for the difference between the width of the current code and the
|
||||
// snippet being suggested, so that the *later* suggestions are correctly
|
||||
// aligned on the screen.
|
||||
acc += len - (cur_hi.col.0 - cur_lo.col.0) as isize;
|
||||
}
|
||||
// Account for the difference between the width of the current code and the
|
||||
// snippet being suggested, so that the *later* suggestions are correctly
|
||||
// aligned on the screen. Note that cur_hi and cur_lo can be on different
|
||||
// lines, so cur_hi.col can be smaller than cur_lo.col
|
||||
acc += len - (cur_hi.col.0 as isize - cur_lo.col.0 as isize);
|
||||
prev_hi = cur_hi;
|
||||
prev_line = sf.get_line(prev_hi.line - 1);
|
||||
for line in part.snippet.split('\n').skip(1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue