Skip to content

Commit bccf49f

Browse files
authored
Rollup merge of rust-lang#64029 - estebank:fix-miri, r=RalfJung
Account for rounding errors when deciding the diagnostic boundaries Fix Miri by fixing the bug raised in rust-lang#63402 (comment). Fixes rust-lang#64020
2 parents 064b704 + 8456719 commit bccf49f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/librustc_errors/emitter.rs

+6-4
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 = self.span_left.saturating_sub(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 = self.span_left.saturating_sub(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;
@@ -1304,11 +1304,13 @@ impl EmitterWriter {
13041304
};
13051305

13061306
let column_width = if let Some(width) = self.terminal_width {
1307-
width
1307+
width.saturating_sub(code_offset)
13081308
} else if self.ui_testing {
13091309
140
13101310
} else {
1311-
term_size::dimensions().map(|(w, _)| w - code_offset).unwrap_or(140)
1311+
term_size::dimensions()
1312+
.map(|(w, _)| w.saturating_sub(code_offset))
1313+
.unwrap_or(std::usize::MAX)
13121314
};
13131315

13141316
let margin = Margin::new(

0 commit comments

Comments
 (0)