about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorMatthijs Hofstra <thiezz@gmail.com>2013-02-09 00:45:00 +0100
committerMatthijs 'Thiez' Hofstra <thiezz@gmail.com>2013-02-09 00:57:39 +0100
commitfd98ea8129d0c4125c15bfc35c68a7c48ae551f3 (patch)
tree3c0923246a95731242b7c3352278c221190df743 /src/libsyntax
parent0c2b4edff5009ff4d2330723d9acbc85af4b12ab (diff)
downloadrust-fd98ea8129d0c4125c15bfc35c68a7c48ae551f3.tar.gz
rust-fd98ea8129d0c4125c15bfc35c68a7c48ae551f3.zip
Fix for issue 2174
The function that formats and prints the squigly line that hilights
errors counted tabs as spaces, which resulted in incorrect error
messages when tabs were used for indentation. This change compares
the highlight line with the previous line and inserts a tab instead
of a space whenever such a tab exists on the previous line. Note
that error messages will still highlight incorrectly when the
previous line include characters that require more than one utf8
code point, as mentioned in issue 3260.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/diagnostic.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs
index cd42fc7a953..1276d5e0ca2 100644
--- a/src/libsyntax/diagnostic.rs
+++ b/src/libsyntax/diagnostic.rs
@@ -263,14 +263,26 @@ fn highlight_lines(cm: @codemap::CodeMap,
         // indent past |name:## | and the 0-offset column location
         let mut left = str::len(fm.name) + digits + lo.col.to_uint() + 3u;
         let mut s = ~"";
-        while left > 0u { str::push_char(&mut s, ' '); left -= 1u; }
-
+        // Skip is the number of characters we need to skip because they are
+        // part of the 'filename:line ' part of the previous line.
+        let skip = str::len(fm.name) + digits + 3u;
+        for skip.times() {
+            s += ~" ";
+        }
+        let orig = fm.get_line(lines.lines[0] as int);
+        for uint::range(0u,left-skip) |pos| {
+            let curChar = (orig[pos] as char);
+            s += match curChar { // Whenever a tab occurs on the previous
+                '\t' => "\t",    // line, we insert one on the error-point-
+                _ => " "         // -squigly-line as well (instead of a
+            };                   // space). This way the squigly-line will
+        }                        // usually appear in the correct position.
         s += ~"^";
         let hi = cm.lookup_char_pos(sp.hi);
         if hi.col != lo.col {
             // the ^ already takes up one space
-            let mut width = hi.col.to_uint() - lo.col.to_uint() - 1u;
-            while width > 0u { str::push_char(&mut s, '~'); width -= 1u; }
+            let num_squiglies = hi.col.to_uint()-lo.col.to_uint()-1u;
+            for num_squiglies.times() { s += ~"~"; }
         }
         io::stderr().write_str(s + ~"\n");
     }