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

DO NOT MERGE: Replace overflowing sub with checked_sub. #134361

Closed
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
9 changes: 8 additions & 1 deletion compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ impl Margin {

if self.computed_right - self.computed_left > self.column_width {
// Trimming only whitespace isn't enough, let's get craftier.
if self.label_right - self.whitespace_left <= self.column_width {

// Note: self.label_right - self.whitespace_left will overflow in the case that the label
// is addressing whitespace. This happens when a spurious no-breaking-space (\u{a0})
// is present in the whitespace.
if let Some(non_whitespace_label_width) =
self.label_right.checked_sub(self.whitespace_left)
&& non_whitespace_label_width <= self.column_width
{
// Attempt to fit the code window only trimming whitespace.
self.computed_left = self.whitespace_left;
self.computed_right = self.computed_left + self.column_width;
Expand Down
Loading