Skip to content

Commit 6d55d3a

Browse files
committed
rollup merge of #22103: pczarn/fix-ice-22091
Fixes #22091 I'm not sure how to write a test for this. An ICE happens with spans that start near (after?) a null character or some other zero-width unicode character.
2 parents 5ad52ca + 89b2e9f commit 6d55d3a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/libsyntax/diagnostic.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,11 @@ fn highlight_lines(err: &mut EmitterWriter,
518518
let count = match lastc {
519519
// Most terminals have a tab stop every eight columns by default
520520
'\t' => 8 - col%8,
521-
_ => lastc.width(false).unwrap_or(1),
521+
_ => lastc.width(false).unwrap_or(0),
522522
};
523523
col += count;
524-
s.extend(::std::iter::repeat('~').take(count - 1));
524+
s.extend(::std::iter::repeat('~').take(count));
525+
525526
let hi = cm.lookup_char_pos(sp.hi);
526527
if hi.col != lo.col {
527528
for (pos, ch) in iter {
@@ -534,6 +535,12 @@ fn highlight_lines(err: &mut EmitterWriter,
534535
s.extend(::std::iter::repeat('~').take(count));
535536
}
536537
}
538+
539+
if s.len() > 1 {
540+
// One extra squiggly is replaced by a "^"
541+
s.pop();
542+
}
543+
537544
try!(print_maybe_styled(err,
538545
&format!("{}\n", s)[],
539546
term::attr::ForegroundColor(lvl.color())));

0 commit comments

Comments
 (0)