about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Wright <mikerite@lavabit.com>2021-10-30 06:22:19 +0200
committerMichael Wright <mikerite@lavabit.com>2021-10-30 06:22:19 +0200
commite8c4046841b43e4b3ea3ff8f5c22858f34c8fe9f (patch)
tree0fa961c9d63ed644b92f79f69d9f7b80cae9bae5
parent4a86156c66a8cb66da85ffe68b90bd0f643e441b (diff)
downloadrust-e8c4046841b43e4b3ea3ff8f5c22858f34c8fe9f.tar.gz
rust-e8c4046841b43e4b3ea3ff8f5c22858f34c8fe9f.zip
Simplify FullInt Ord impl
`cmp_s_u` is a tiny helper function only used by `cmp` and isn't useful on
it's own. Making it a nested function of `cmp` makes that clear and as a
bonus it's easier to call and doesn't require a `#[must_use]` attribute.
-rw-r--r--clippy_utils/src/consts.rs15
1 files changed, 6 insertions, 9 deletions
diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs
index e40a1d2f279..04347672e0f 100644
--- a/clippy_utils/src/consts.rs
+++ b/clippy_utils/src/consts.rs
@@ -229,13 +229,6 @@ pub enum FullInt {
     U(u128),
 }
 
-impl FullInt {
-    #[must_use]
-    fn cmp_s_u(s: i128, u: u128) -> Ordering {
-        u128::try_from(s).map_or(Ordering::Less, |x| x.cmp(&u))
-    }
-}
-
 impl PartialEq for FullInt {
     #[must_use]
     fn eq(&self, other: &Self) -> bool {
@@ -255,11 +248,15 @@ impl Ord for FullInt {
     fn cmp(&self, other: &Self) -> Ordering {
         use FullInt::{S, U};
 
+        fn cmp_s_u(s: i128, u: u128) -> Ordering {
+            u128::try_from(s).map_or(Ordering::Less, |x| x.cmp(&u))
+        }
+
         match (*self, *other) {
             (S(s), S(o)) => s.cmp(&o),
             (U(s), U(o)) => s.cmp(&o),
-            (S(s), U(o)) => Self::cmp_s_u(s, o),
-            (U(s), S(o)) => Self::cmp_s_u(o, s).reverse(),
+            (S(s), U(o)) => cmp_s_u(s, o),
+            (U(s), S(o)) => cmp_s_u(o, s).reverse(),
         }
     }
 }