Skip to content

Commit 955e913

Browse files
committed
review comments
1 parent 31d07ed commit 955e913

File tree

1 file changed

+26
-5
lines changed
  • compiler/rustc_errors/src

1 file changed

+26
-5
lines changed

compiler/rustc_errors/src/lib.rs

+26-5
Original file line numberDiff line numberDiff line change
@@ -321,21 +321,42 @@ impl CodeSuggestion {
321321
}
322322
}
323323
// Add a whole line highlight per line in the snippet.
324-
let len = part.snippet.split('\n').next().unwrap_or(&part.snippet).len();
324+
let len: isize = part
325+
.snippet
326+
.split('\n')
327+
.next()
328+
.unwrap_or(&part.snippet)
329+
.chars()
330+
.map(|c| match c {
331+
'\t' => 4,
332+
_ => 1,
333+
})
334+
.sum();
325335
line_highlight.push(SubstitutionHighlight {
326336
start: (cur_lo.col.0 as isize + acc) as usize,
327-
end: (cur_lo.col.0 as isize + acc + len as isize) as usize,
337+
end: (cur_lo.col.0 as isize + acc + len) as usize,
328338
});
329339
buf.push_str(&part.snippet);
330-
prev_hi = sm.lookup_char_pos(part.span.hi());
340+
let cur_hi = sm.lookup_char_pos(part.span.hi());
331341
if prev_hi.line == cur_lo.line {
332-
acc += len as isize - (prev_hi.col.0 - cur_lo.col.0) as isize;
342+
// Account for the difference between the width of the current code and the
343+
// snippet being suggested, so that the *later* suggestions are correctly
344+
// aligned on the screen.
345+
acc += len as isize - (cur_hi.col.0 - cur_lo.col.0) as isize;
333346
}
347+
prev_hi = cur_hi;
334348
prev_line = sf.get_line(prev_hi.line - 1);
335349
for line in part.snippet.split('\n').skip(1) {
336350
acc = 0;
337351
highlights.push(std::mem::take(&mut line_highlight));
338-
line_highlight.push(SubstitutionHighlight { start: 0, end: line.len() });
352+
let end: usize = line
353+
.chars()
354+
.map(|c| match c {
355+
'\t' => 4,
356+
_ => 1,
357+
})
358+
.sum();
359+
line_highlight.push(SubstitutionHighlight { start: 0, end });
339360
}
340361
}
341362
highlights.push(std::mem::take(&mut line_highlight));

0 commit comments

Comments
 (0)