Skip to content

Commit 599bf45

Browse files
tbelaireOliver Schneider
authored and
Oliver Schneider
committed
Indent code past the widest line number
Fixes rust-lang#11715
1 parent e749f72 commit 599bf45

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libsyntax/diagnostic.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,18 @@ fn highlight_lines(err: &mut EmitterWriter,
594594
let display_line_infos = &lines.lines[..display_lines];
595595
let display_line_strings = &line_strings[..display_lines];
596596

597+
// Calculate the widest number to format evenly and fix #11715
598+
assert!(display_line_infos.len() > 0);
599+
let mut max_line_num = display_line_infos[display_line_infos.len() - 1].line_index + 1;
600+
let mut digits = 0;
601+
while max_line_num > 0 { max_line_num /= 10; digits += 1; }
597602
// Print the offending lines
598603
for (line_info, line) in display_line_infos.iter().zip(display_line_strings) {
599-
try!(write!(&mut err.dst, "{}:{} {}\n",
604+
try!(write!(&mut err.dst, "{}:{:>width$} {}\n",
600605
fm.name,
601606
line_info.line_index + 1,
602-
line));
607+
line,
608+
width=digits));
603609
}
604610

605611
// If we elided something, put an ellipsis.

0 commit comments

Comments
 (0)