Skip to content

Commit 8456719

Browse files
committed
Use saturating_sub
1 parent bf90154 commit 8456719

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 = max(self.span_left, padding_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 = max(self.span_left, padding_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-
max(width, code_offset) - code_offset
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(std::usize::MAX)
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)