Skip to content
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

Account for rounding errors when deciding the diagnostic boundaries #64029

Merged
merged 3 commits into from
Sep 1, 2019
Merged
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: 6 additions & 4 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ impl Margin {
} else if self.label_right - self.span_left <= self.column_width {
// Attempt to fit the code window considering only the spans and labels.
let padding_left = (self.column_width - (self.label_right - self.span_left)) / 2;
self.computed_left = self.span_left - padding_left;
self.computed_left = self.span_left.saturating_sub(padding_left);
self.computed_right = self.computed_left + self.column_width;
} else if self.span_right - self.span_left <= self.column_width {
// Attempt to fit the code window considering the spans and labels plus padding.
let padding_left = (self.column_width - (self.span_right - self.span_left)) / 5 * 2;
self.computed_left = self.span_left - padding_left;
self.computed_left = self.span_left.saturating_sub(padding_left);
self.computed_right = self.computed_left + self.column_width;
} else { // Mostly give up but still don't show the full line.
self.computed_left = self.span_left;
Expand Down Expand Up @@ -1304,11 +1304,13 @@ impl EmitterWriter {
};

let column_width = if let Some(width) = self.terminal_width {
width
width.saturating_sub(code_offset)
} else if self.ui_testing {
140
} else {
term_size::dimensions().map(|(w, _)| w - code_offset).unwrap_or(140)
term_size::dimensions()
.map(|(w, _)| w.saturating_sub(code_offset))
.unwrap_or(std::usize::MAX)
Copy link
Member

Choose a reason for hiding this comment

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

Why was this changed to usize::MAX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bjorn3 If the dimensions aren't supplied and can't be queried, I decided that keeping the current uncropped behavior makes more sense. By setting it to MAX it'll never crop.

};

let margin = Margin::new(
Expand Down