Skip to content

Indent code past the widest line number #25037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/libsyntax/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,18 @@ fn highlight_lines(err: &mut EmitterWriter,
let display_line_infos = &lines.lines[..display_lines];
let display_line_strings = &line_strings[..display_lines];

// Calculate the widest number to format evenly and fix #11715
assert!(display_line_infos.len() > 0);
let mut max_line_num = display_line_infos[display_line_infos.len() - 1].line_index + 1;
let mut digits = 0;
while max_line_num > 0 { max_line_num /= 10; digits += 1; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit this would better to be split across multiple lines

// Print the offending lines
for (line_info, line) in display_line_infos.iter().zip(display_line_strings.iter()) {
try!(write!(&mut err.dst, "{}:{} {}\n",
try!(write!(&mut err.dst, "{}:{:>width$} {}\n",
fm.name,
line_info.line_index + 1,
line));
line,
width=digits));
}

// If we elided something, put an ellipsis.
Expand Down