Skip to content

Commit 7fe6b1b

Browse files
committed
auto merge of #4853 : Thiez/rust/incoming, r=catamorphism
A simple fix for issue 2174.
2 parents 19dfec2 + 8d0c1cb commit 7fe6b1b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/libsyntax/diagnostic.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ fn highlight_lines(cm: @codemap::CodeMap,
250250
io::stderr().write_str(out);
251251
}
252252

253-
253+
// FIXME (#3260)
254254
// If there's one line at fault we can easily point to the problem
255255
if vec::len(lines.lines) == 1u {
256256
let lo = cm.lookup_char_pos(sp.lo);
@@ -263,14 +263,26 @@ fn highlight_lines(cm: @codemap::CodeMap,
263263
// indent past |name:## | and the 0-offset column location
264264
let mut left = str::len(fm.name) + digits + lo.col.to_uint() + 3u;
265265
let mut s = ~"";
266-
while left > 0u { str::push_char(&mut s, ' '); left -= 1u; }
267-
266+
// Skip is the number of characters we need to skip because they are
267+
// part of the 'filename:line ' part of the previous line.
268+
let skip = str::len(fm.name) + digits + 3u;
269+
for skip.times() {
270+
s += ~" ";
271+
}
272+
let orig = fm.get_line(lines.lines[0] as int);
273+
for uint::range(0u,left-skip) |pos| {
274+
let curChar = (orig[pos] as char);
275+
s += match curChar { // Whenever a tab occurs on the previous
276+
'\t' => "\t", // line, we insert one on the error-point-
277+
_ => " " // -squigly-line as well (instead of a
278+
}; // space). This way the squigly-line will
279+
} // usually appear in the correct position.
268280
s += ~"^";
269281
let hi = cm.lookup_char_pos(sp.hi);
270282
if hi.col != lo.col {
271283
// the ^ already takes up one space
272-
let mut width = hi.col.to_uint() - lo.col.to_uint() - 1u;
273-
while width > 0u { str::push_char(&mut s, '~'); width -= 1u; }
284+
let num_squiglies = hi.col.to_uint()-lo.col.to_uint()-1u;
285+
for num_squiglies.times() { s += ~"~"; }
274286
}
275287
io::stderr().write_str(s + ~"\n");
276288
}

0 commit comments

Comments
 (0)