diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-03-27 21:41:50 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-27 21:41:50 -0400 |
| commit | 2465b628583e0f60baedecea237f56234855747b (patch) | |
| tree | d1fb2c12f7ac39b669bc9a3f4caf82ecbd774b56 /compiler | |
| parent | d837ab4489003cacfc0fd3f3df459db3d05e1edf (diff) | |
| parent | bec69704c0ee6b3c6b1854b104b964fc17d8c36f (diff) | |
| download | rust-2465b628583e0f60baedecea237f56234855747b.tar.gz rust-2465b628583e0f60baedecea237f56234855747b.zip | |
Rollup merge of #139026 - yotamofek:pr/abs-diff, r=compiler-errors
Use `abs_diff` where applicable Very small cleanup, dogfooding a [new clippy lint](https://github.com/rust-lang/rust-clippy/pull/14482) I'm trying to add
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_errors/src/snippet.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_span/src/edit_distance.rs | 2 |
2 files changed, 2 insertions, 6 deletions
diff --git a/compiler/rustc_errors/src/snippet.rs b/compiler/rustc_errors/src/snippet.rs index 8485d7087cf..f09c2ed5534 100644 --- a/compiler/rustc_errors/src/snippet.rs +++ b/compiler/rustc_errors/src/snippet.rs @@ -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 { diff --git a/compiler/rustc_span/src/edit_distance.rs b/compiler/rustc_span/src/edit_distance.rs index 8a2baaa42e2..4f3202b694c 100644 --- a/compiler/rustc_span/src/edit_distance.rs +++ b/compiler/rustc_span/src/edit_distance.rs @@ -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 |
