Skip to content

Use abs_diff where applicable #139026

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

Merged
merged 1 commit into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 1 addition & 5 deletions compiler/rustc_errors/src/snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@ impl Annotation {
/// Length of this annotation as displayed in the stderr output
pub(crate) fn len(&self) -> usize {
// Account for usize underflows
if self.end_col.display > self.start_col.display {
self.end_col.display - self.start_col.display
} else {
self.start_col.display - self.end_col.display
}
self.end_col.display.abs_diff(self.start_col.display)
}

pub(crate) fn has_label(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/edit_distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn edit_distance_with_substrings(a: &str, b: &str, limit: usize) -> Option<u
// Check one isn't less than half the length of the other. If this is true then there is a
// big difference in length.
let big_len_diff = (n * 2) < m || (m * 2) < n;
let len_diff = if n < m { m - n } else { n - m };
let len_diff = m.abs_diff(n);
let distance = edit_distance(a, b, limit + len_diff)?;

// This is the crux, subtracting length difference means exact substring matches will now be 0
Expand Down
Loading