about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-02-10 08:42:49 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-02-10 08:42:49 -0800
commit6d55d3ac454fd57b32016aee280560247727f219 (patch)
tree2012cf46c26137a2ce2ad7221773b7278e350ebe /src/libsyntax
parent5ad52ca6b39b4635fca7f85168e14bff48aed8c4 (diff)
parent89b2e9f6f34ce00b3d6c24650922de26c8ed1e44 (diff)
downloadrust-6d55d3ac454fd57b32016aee280560247727f219.tar.gz
rust-6d55d3ac454fd57b32016aee280560247727f219.zip
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.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/diagnostic.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs
index 454209bdba2..83a4d938bb5 100644
--- a/src/libsyntax/diagnostic.rs
+++ b/src/libsyntax/diagnostic.rs
@@ -518,10 +518,11 @@ fn highlight_lines(err: &mut EmitterWriter,
             let count = match lastc {
                 // Most terminals have a tab stop every eight columns by default
                 '\t' => 8 - col%8,
-                _ => lastc.width(false).unwrap_or(1),
+                _ => lastc.width(false).unwrap_or(0),
             };
             col += count;
-            s.extend(::std::iter::repeat('~').take(count - 1));
+            s.extend(::std::iter::repeat('~').take(count));
+
             let hi = cm.lookup_char_pos(sp.hi);
             if hi.col != lo.col {
                 for (pos, ch) in iter {
@@ -534,6 +535,12 @@ fn highlight_lines(err: &mut EmitterWriter,
                     s.extend(::std::iter::repeat('~').take(count));
                 }
             }
+
+            if s.len() > 1 {
+                // One extra squiggly is replaced by a "^"
+                s.pop();
+            }
+
             try!(print_maybe_styled(err,
                                     &format!("{}\n", s)[],
                                     term::attr::ForegroundColor(lvl.color())));