mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Use abs_diff where applicable
This commit is contained in:
@@ -159,11 +159,7 @@ pub(crate) fn is_line(&self) -> bool {
|
||||
/// 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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user