Skip to content

Commit bec6970

Browse files
committed
Use abs_diff where applicable
1 parent ecb170a commit bec6970

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

Diff for: compiler/rustc_errors/src/snippet.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,7 @@ impl Annotation {
159159
/// Length of this annotation as displayed in the stderr output
160160
pub(crate) fn len(&self) -> usize {
161161
// Account for usize underflows
162-
if self.end_col.display > self.start_col.display {
163-
self.end_col.display - self.start_col.display
164-
} else {
165-
self.start_col.display - self.end_col.display
166-
}
162+
self.end_col.display.abs_diff(self.start_col.display)
167163
}
168164

169165
pub(crate) fn has_label(&self) -> bool {

Diff for: compiler/rustc_span/src/edit_distance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub fn edit_distance_with_substrings(a: &str, b: &str, limit: usize) -> Option<u
118118
// Check one isn't less than half the length of the other. If this is true then there is a
119119
// big difference in length.
120120
let big_len_diff = (n * 2) < m || (m * 2) < n;
121-
let len_diff = if n < m { m - n } else { n - m };
121+
let len_diff = m.abs_diff(n);
122122
let distance = edit_distance(a, b, limit + len_diff)?;
123123

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

0 commit comments

Comments
 (0)