Skip to content

Commit 2465b62

Browse files
authored
Rollup merge of #139026 - yotamofek:pr/abs-diff, r=compiler-errors
Use `abs_diff` where applicable Very small cleanup, dogfooding a [new clippy lint](rust-lang/rust-clippy#14482) I'm trying to add
2 parents d837ab4 + bec6970 commit 2465b62

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

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 {

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)