Skip to content

Commit e8c4046

Browse files
author
Michael Wright
committed
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.
1 parent 4a86156 commit e8c4046

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

clippy_utils/src/consts.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,6 @@ pub enum FullInt {
229229
U(u128),
230230
}
231231

232-
impl FullInt {
233-
#[must_use]
234-
fn cmp_s_u(s: i128, u: u128) -> Ordering {
235-
u128::try_from(s).map_or(Ordering::Less, |x| x.cmp(&u))
236-
}
237-
}
238-
239232
impl PartialEq for FullInt {
240233
#[must_use]
241234
fn eq(&self, other: &Self) -> bool {
@@ -255,11 +248,15 @@ impl Ord for FullInt {
255248
fn cmp(&self, other: &Self) -> Ordering {
256249
use FullInt::{S, U};
257250

251+
fn cmp_s_u(s: i128, u: u128) -> Ordering {
252+
u128::try_from(s).map_or(Ordering::Less, |x| x.cmp(&u))
253+
}
254+
258255
match (*self, *other) {
259256
(S(s), S(o)) => s.cmp(&o),
260257
(U(s), U(o)) => s.cmp(&o),
261-
(S(s), U(o)) => Self::cmp_s_u(s, o),
262-
(U(s), S(o)) => Self::cmp_s_u(o, s).reverse(),
258+
(S(s), U(o)) => cmp_s_u(s, o),
259+
(U(s), S(o)) => cmp_s_u(o, s).reverse(),
263260
}
264261
}
265262
}

0 commit comments

Comments
 (0)