From 477947b156bef658f5bbbb1febe76c0c12e71901 Mon Sep 17 00:00:00 2001 From: Andrew Kubera Date: Sun, 8 Dec 2024 13:57:43 -0500 Subject: [PATCH] Fix clippy lints --- src/arithmetic/cbrt.rs | 15 ++++++++++----- src/arithmetic/mod.rs | 1 + src/arithmetic/sqrt.rs | 2 +- src/impl_fmt.rs | 6 +++--- src/impl_num.rs | 12 ++++++------ src/impl_ops.rs | 2 +- src/impl_ops_add.rs | 8 ++++---- src/impl_ops_div.rs | 2 +- src/impl_ops_mul.rs | 20 ++++++++++---------- src/impl_ops_rem.rs | 6 +++--- src/impl_trait_from_str.rs | 2 +- src/lib.rs | 7 +++++-- src/with_std.rs | 1 - 13 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/arithmetic/cbrt.rs b/src/arithmetic/cbrt.rs index a75b0cf..beb6e51 100644 --- a/src/arithmetic/cbrt.rs +++ b/src/arithmetic/cbrt.rs @@ -46,11 +46,16 @@ pub(crate) fn impl_cbrt_uint_scale( let (mut new_scale, remainder) = shifted_scale.div_rem(&3); - if remainder > 0 { - new_scale += 1; - exp_shift += (3 - remainder) as u64; - } else if remainder < 0 { - exp_shift += remainder.neg() as u64; + match remainder.cmp(&0) { + Ordering::Greater => { + new_scale += 1; + exp_shift += (3 - remainder) as u64; + } + Ordering::Less => { + exp_shift += remainder.neg() as u64; + } + Ordering::Equal => { + } } // clone-on-write copy of digits diff --git a/src/arithmetic/mod.rs b/src/arithmetic/mod.rs index 9cfb561..07bcf18 100644 --- a/src/arithmetic/mod.rs +++ b/src/arithmetic/mod.rs @@ -145,6 +145,7 @@ pub(crate) fn abs_diff(x: i64, y: i64) -> u64 { } #[cfg(not(rustc_1_60))] +#[allow(dead_code)] pub(crate) fn abs_diff(x: i64, y: i64) -> u64 { (x as i128 - y as i128).to_u64().unwrap_or(0) } diff --git a/src/arithmetic/sqrt.rs b/src/arithmetic/sqrt.rs index d0c0ff8..23ddfff 100644 --- a/src/arithmetic/sqrt.rs +++ b/src/arithmetic/sqrt.rs @@ -5,7 +5,7 @@ use crate::*; pub(crate) fn impl_sqrt(n: &BigUint, scale: i64, ctx: &Context) -> BigDecimal { // Calculate the number of digits and the difference compared to the scale - let num_digits = count_decimal_digits_uint(&n); + let num_digits = count_decimal_digits_uint(n); let scale_diff = BigInt::from(num_digits) - scale; // Calculate the number of wanted digits and the exponent we need to raise the original value to diff --git a/src/impl_fmt.rs b/src/impl_fmt.rs index e791b58..d55f71e 100644 --- a/src/impl_fmt.rs +++ b/src/impl_fmt.rs @@ -109,7 +109,7 @@ fn dynamically_format_decimal( // use exponential form if decimal point is outside // the upper and lower thresholds of the decimal, // and precision was not requested - if matches!(f.precision(), None) && leading_zero_threshold < leading_zero_count { + if f.precision().is_none() && leading_zero_threshold < leading_zero_count { format_exponential(this, f, abs_int, "E") } else if trailing_zero_threshold < trailing_zeros { // non-scientific notation @@ -122,7 +122,7 @@ fn dynamically_format_decimal( pub(crate) struct FullScaleFormatter<'a>(pub BigDecimalRef<'a>); -impl<'a> fmt::Display for FullScaleFormatter<'a> { +impl fmt::Display for FullScaleFormatter<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let n = self.0; let non_negative = matches!(n.sign, Sign::Plus | Sign::NoSign); @@ -222,7 +222,7 @@ fn zero_right_pad_integer_ascii_digits( // did not explicitly request precision, so we'll only // implicitly right-pad if less than this threshold. - if matches!(target_scale, None) && integer_zero_count > 20 { + if target_scale.is_none() && integer_zero_count > 20 { // no padding return; } diff --git a/src/impl_num.rs b/src/impl_num.rs index c5ca352..ac5df68 100644 --- a/src/impl_num.rs +++ b/src/impl_num.rs @@ -126,7 +126,7 @@ impl ToPrimitive for BigDecimal { } } -impl<'a> ToPrimitive for BigDecimalRef<'a> { +impl ToPrimitive for BigDecimalRef<'_> { fn to_i64(&self) -> Option { match self.sign() { Sign::Plus if self.scale == 0 => self.digits.to_i64(), @@ -237,9 +237,9 @@ impl<'a> ToPrimitive for BigDecimalRef<'a> { None => { // exponenent too big for i32: return appropriate infinity let result = if self.sign != Sign::Minus { - stdlib::f64::INFINITY + f64::INFINITY } else { - stdlib::f64::NEG_INFINITY + f64::NEG_INFINITY }; result.into() } @@ -331,9 +331,9 @@ mod test { impl_case!(case_zero: 0.0); impl_case!(case_neg_zero: -0.0); impl_case!(case_875en6: 0.000875); - impl_case!(case_f64_min: stdlib::f64::MIN); - impl_case!(case_f64_max: stdlib::f64::MAX); - impl_case!(case_f64_min_pos: stdlib::f64::MIN_POSITIVE); + impl_case!(case_f64_min: f64::MIN); + impl_case!(case_f64_max: f64::MAX); + impl_case!(case_f64_min_pos: f64::MIN_POSITIVE); impl_case!(case_pi: stdlib::f64::consts::PI); impl_case!(case_neg_e: -stdlib::f64::consts::E); impl_case!(case_1en500: 1e-500); diff --git a/src/impl_ops.rs b/src/impl_ops.rs index 784a4e0..a52b8a0 100644 --- a/src/impl_ops.rs +++ b/src/impl_ops.rs @@ -449,7 +449,7 @@ impl Neg for BigDecimal { } } -impl<'a> Neg for &'a BigDecimal { +impl Neg for &BigDecimal { type Output = BigDecimal; #[inline] diff --git a/src/impl_ops_add.rs b/src/impl_ops_add.rs index ac099e4..4322302 100644 --- a/src/impl_ops_add.rs +++ b/src/impl_ops_add.rs @@ -95,7 +95,7 @@ impl Add for BigInt { } } -impl<'a> Add<&'a BigDecimal> for BigInt { +impl Add<&BigDecimal> for BigInt { type Output = BigDecimal; fn add(self, rhs: &BigDecimal) -> BigDecimal { @@ -103,7 +103,7 @@ impl<'a> Add<&'a BigDecimal> for BigInt { } } -impl<'a> Add> for BigInt { +impl Add> for BigInt { type Output = BigDecimal; fn add(self, rhs: BigDecimalRef<'_>) -> BigDecimal { @@ -121,7 +121,7 @@ impl Add for &BigInt { } } -impl<'a> Add<&'a BigDecimal> for &BigInt { +impl Add<&BigDecimal> for &BigInt { type Output = BigDecimal; #[inline] @@ -130,7 +130,7 @@ impl<'a> Add<&'a BigDecimal> for &BigInt { } } -impl<'a> Add> for &BigInt { +impl Add> for &BigInt { type Output = BigDecimal; #[inline] diff --git a/src/impl_ops_div.rs b/src/impl_ops_div.rs index 9f36b9f..99aef24 100644 --- a/src/impl_ops_div.rs +++ b/src/impl_ops_div.rs @@ -56,7 +56,7 @@ impl<'a> Div<&'a BigDecimal> for BigDecimal { forward_ref_val_binop!(impl Div for BigDecimal, div); -impl<'a, 'b> Div<&'b BigDecimal> for &'a BigDecimal { +impl Div<&BigDecimal> for &BigDecimal { type Output = BigDecimal; #[inline] diff --git a/src/impl_ops_mul.rs b/src/impl_ops_mul.rs index a1cbc43..3a24897 100644 --- a/src/impl_ops_mul.rs +++ b/src/impl_ops_mul.rs @@ -42,7 +42,7 @@ impl<'a> Mul<&'a BigDecimal> for BigDecimal { } } -impl<'a> Mul for &'a BigDecimal { +impl Mul for &BigDecimal { type Output = BigDecimal; #[inline] @@ -51,7 +51,7 @@ impl<'a> Mul for &'a BigDecimal { } } -impl<'a, 'b> Mul<&'b BigDecimal> for &'a BigDecimal { +impl Mul<&BigDecimal> for &BigDecimal { type Output = BigDecimal; #[inline] @@ -77,7 +77,7 @@ impl Mul for BigDecimal { } } -impl<'a> Mul<&'a BigInt> for BigDecimal { +impl Mul<&BigInt> for BigDecimal { type Output = BigDecimal; #[inline] @@ -87,7 +87,7 @@ impl<'a> Mul<&'a BigInt> for BigDecimal { } } -impl<'a> Mul for &'a BigDecimal { +impl Mul for &BigDecimal { type Output = BigDecimal; #[inline] @@ -97,7 +97,7 @@ impl<'a> Mul for &'a BigDecimal { } } -impl<'a, 'b> Mul<&'a BigInt> for &'b BigDecimal { +impl Mul<&BigInt> for &BigDecimal { type Output = BigDecimal; #[inline] @@ -128,7 +128,7 @@ impl Mul for BigInt { } } -impl<'a> Mul for &'a BigInt { +impl Mul for &BigInt { type Output = BigDecimal; #[inline] @@ -147,7 +147,7 @@ impl<'a> Mul for &'a BigInt { } } -impl<'a, 'b> Mul<&'a BigDecimal> for &'b BigInt { +impl Mul<&BigDecimal> for &BigInt { type Output = BigDecimal; #[inline] @@ -163,7 +163,7 @@ impl<'a, 'b> Mul<&'a BigDecimal> for &'b BigInt { } } -impl<'a> Mul<&'a BigDecimal> for BigInt { +impl Mul<&BigDecimal> for BigInt { type Output = BigDecimal; #[inline] @@ -181,7 +181,7 @@ impl<'a> Mul<&'a BigDecimal> for BigInt { forward_val_assignop!(impl MulAssign for BigDecimal, mul_assign); -impl<'a> MulAssign<&'a BigDecimal> for BigDecimal { +impl MulAssign<&BigDecimal> for BigDecimal { #[inline] fn mul_assign(&mut self, rhs: &BigDecimal) { if rhs.is_one() { @@ -192,7 +192,7 @@ impl<'a> MulAssign<&'a BigDecimal> for BigDecimal { } } -impl<'a> MulAssign<&'a BigInt> for BigDecimal { +impl MulAssign<&BigInt> for BigDecimal { #[inline] fn mul_assign(&mut self, rhs: &BigInt) { if rhs.is_one() { diff --git a/src/impl_ops_rem.rs b/src/impl_ops_rem.rs index 56bad43..6b3e9bf 100644 --- a/src/impl_ops_rem.rs +++ b/src/impl_ops_rem.rs @@ -17,7 +17,7 @@ impl Rem for BigDecimal { } } -impl<'a> Rem<&'a BigDecimal> for BigDecimal { +impl Rem<&BigDecimal> for BigDecimal { type Output = BigDecimal; #[inline] @@ -35,7 +35,7 @@ impl<'a> Rem<&'a BigDecimal> for BigDecimal { } } -impl<'a> Rem for &'a BigDecimal { +impl Rem for &BigDecimal { type Output = BigDecimal; #[inline] @@ -55,7 +55,7 @@ impl<'a> Rem for &'a BigDecimal { } } -impl<'a, 'b> Rem<&'b BigDecimal> for &'a BigDecimal { +impl Rem<&BigDecimal> for &BigDecimal { type Output = BigDecimal; #[inline] diff --git a/src/impl_trait_from_str.rs b/src/impl_trait_from_str.rs index 4dd760f..c54065f 100644 --- a/src/impl_trait_from_str.rs +++ b/src/impl_trait_from_str.rs @@ -22,7 +22,7 @@ mod tests { fn $name() { let dec = BigDecimal::from_str($input).unwrap(); assert_eq!(dec.int_val, $int.into()); - assert_eq!(dec.scale, -$exp); + assert_eq!(dec.scale, -($exp)); } }; } diff --git a/src/lib.rs b/src/lib.rs index ca541e2..7f089e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,11 +43,14 @@ #![allow(clippy::style)] #![allow(clippy::excessive_precision)] #![allow(clippy::unreadable_literal)] +#![allow(clippy::unusual_byte_groupings)] +#![allow(clippy::needless_late_init)] #![allow(clippy::needless_return)] #![allow(clippy::suspicious_arithmetic_impl)] #![allow(clippy::suspicious_op_assign_impl)] #![allow(clippy::redundant_field_names)] #![allow(clippy::approx_constant)] +#![allow(clippy::wrong_self_convention)] #![cfg_attr(test, allow(clippy::useless_vec))] #![allow(unused_imports)] @@ -1984,12 +1987,12 @@ mod bigdecimal_tests { ]; for s in true_vals { - let d = BigDecimal::from_str(&s).unwrap(); + let d = BigDecimal::from_str(s).unwrap(); assert!(d.is_integer()); } for s in false_vals { - let d = BigDecimal::from_str(&s).unwrap(); + let d = BigDecimal::from_str(s).unwrap(); assert!(!d.is_integer()); } } diff --git a/src/with_std.rs b/src/with_std.rs index 0d0ef58..1d127cf 100644 --- a/src/with_std.rs +++ b/src/with_std.rs @@ -16,7 +16,6 @@ mod stdlib { slice, str, string, - i8, f32, f64, };