diff --git a/src/cmp.rs b/src/cmp.rs index 984341f9..47ede059 100644 --- a/src/cmp.rs +++ b/src/cmp.rs @@ -39,8 +39,8 @@ macro_rules! impl_for_primitives { #[inline] #[allow(unused_comparisons)] // Both signed and unsigned integers use this. #[allow(clippy::cast_possible_truncation)] // Unreachable. - fn partial_cmp(&self, other: &$t) -> Option { - if *other < 0 { + fn partial_cmp(&self, &other: &$t) -> Option { + if other < 0 { return Some(Ordering::Greater); } @@ -48,12 +48,12 @@ macro_rules! impl_for_primitives { let Ok(self_t) = u64::try_from(self) else { return Some(Ordering::Greater); }; - self_t.partial_cmp(&(*other as u64)) + self_t.partial_cmp(&(other as u64)) } else { let Ok(self_t) = u128::try_from(self) else { return Some(Ordering::Greater); }; - self_t.partial_cmp(&(*other as u128)) + self_t.partial_cmp(&(other as u128)) } } } diff --git a/src/fmt.rs b/src/fmt.rs index 2465df9a..09c530dd 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -55,6 +55,13 @@ macro_rules! impl_fmt { ($tr:path; $base:ty, $base_char:literal) => { impl $tr for Uint { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if let Ok(small) = u64::try_from(self) { + return ::fmt(&small, f); + } + if let Ok(small) = u128::try_from(self) { + return ::fmt(&small, f); + } + // Use `BITS` for all bases since `generic_const_exprs` is not yet stable. let mut buffer = DisplayBuffer::::new(); let mut first = true;