Skip to content

Commit

Permalink
Simplify FullInt Ord impl
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
Michael Wright committed Oct 30, 2021
1 parent 4a86156 commit e8c4046
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions clippy_utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
}
}
}
Expand Down

0 comments on commit e8c4046

Please sign in to comment.