Skip to content

Commit 78f62c6

Browse files
committed
Account for rounding errors when deciding the diagnostic boundaries
1 parent 4295eea commit 78f62c6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/librustc_errors/emitter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ impl Margin {
146146
} else if self.label_right - self.span_left <= self.column_width {
147147
// Attempt to fit the code window considering only the spans and labels.
148148
let padding_left = (self.column_width - (self.label_right - self.span_left)) / 2;
149-
self.computed_left = self.span_left - padding_left;
149+
self.computed_left = max(self.span_left, padding_left) - padding_left;
150150
self.computed_right = self.computed_left + self.column_width;
151151
} else if self.span_right - self.span_left <= self.column_width {
152152
// Attempt to fit the code window considering the spans and labels plus padding.
153153
let padding_left = (self.column_width - (self.span_right - self.span_left)) / 5 * 2;
154-
self.computed_left = self.span_left - padding_left;
154+
self.computed_left = max(self.span_left, padding_left) - padding_left;
155155
self.computed_right = self.computed_left + self.column_width;
156156
} else { // Mostly give up but still don't show the full line.
157157
self.computed_left = self.span_left;

0 commit comments

Comments
 (0)