mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
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.
This commit is contained in:
parent
4a86156c66
commit
e8c4046841
1 changed files with 6 additions and 9 deletions
|
@ -229,13 +229,6 @@ pub enum FullInt {
|
||||||
U(u128),
|
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 {
|
impl PartialEq for FullInt {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
@ -255,11 +248,15 @@ impl Ord for FullInt {
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
use FullInt::{S, U};
|
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) {
|
match (*self, *other) {
|
||||||
(S(s), S(o)) => s.cmp(&o),
|
(S(s), S(o)) => s.cmp(&o),
|
||||||
(U(s), U(o)) => s.cmp(&o),
|
(U(s), U(o)) => s.cmp(&o),
|
||||||
(S(s), U(o)) => Self::cmp_s_u(s, o),
|
(S(s), U(o)) => cmp_s_u(s, o),
|
||||||
(U(s), S(o)) => Self::cmp_s_u(o, s).reverse(),
|
(U(s), S(o)) => cmp_s_u(o, s).reverse(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue