Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
akubera committed Dec 8, 2024
1 parent b797393 commit 477947b
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 38 deletions.
15 changes: 10 additions & 5 deletions src/arithmetic/cbrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/arithmetic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/sqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/impl_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions src/impl_num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl ToPrimitive for BigDecimal {
}
}

impl<'a> ToPrimitive for BigDecimalRef<'a> {
impl ToPrimitive for BigDecimalRef<'_> {
fn to_i64(&self) -> Option<i64> {
match self.sign() {
Sign::Plus if self.scale == 0 => self.digits.to_i64(),
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/impl_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl Neg for BigDecimal {
}
}

impl<'a> Neg for &'a BigDecimal {
impl Neg for &BigDecimal {
type Output = BigDecimal;

#[inline]
Expand Down
8 changes: 4 additions & 4 deletions src/impl_ops_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ impl Add<BigDecimal> for BigInt {
}
}

impl<'a> Add<&'a BigDecimal> for BigInt {
impl Add<&BigDecimal> for BigInt {
type Output = BigDecimal;

fn add(self, rhs: &BigDecimal) -> BigDecimal {
BigDecimal::from(self) + rhs
}
}

impl<'a> Add<BigDecimalRef<'a>> for BigInt {
impl Add<BigDecimalRef<'_>> for BigInt {
type Output = BigDecimal;

fn add(self, rhs: BigDecimalRef<'_>) -> BigDecimal {
Expand All @@ -121,7 +121,7 @@ impl Add<BigDecimal> for &BigInt {
}
}

impl<'a> Add<&'a BigDecimal> for &BigInt {
impl Add<&BigDecimal> for &BigInt {
type Output = BigDecimal;

#[inline]
Expand All @@ -130,7 +130,7 @@ impl<'a> Add<&'a BigDecimal> for &BigInt {
}
}

impl<'a> Add<BigDecimalRef<'a>> for &BigInt {
impl Add<BigDecimalRef<'_>> for &BigInt {
type Output = BigDecimal;

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/impl_ops_div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
20 changes: 10 additions & 10 deletions src/impl_ops_mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'a> Mul<&'a BigDecimal> for BigDecimal {
}
}

impl<'a> Mul<BigDecimal> for &'a BigDecimal {
impl Mul<BigDecimal> for &BigDecimal {
type Output = BigDecimal;

#[inline]
Expand All @@ -51,7 +51,7 @@ impl<'a> Mul<BigDecimal> for &'a BigDecimal {
}
}

impl<'a, 'b> Mul<&'b BigDecimal> for &'a BigDecimal {
impl Mul<&BigDecimal> for &BigDecimal {
type Output = BigDecimal;

#[inline]
Expand All @@ -77,7 +77,7 @@ impl Mul<BigInt> for BigDecimal {
}
}

impl<'a> Mul<&'a BigInt> for BigDecimal {
impl Mul<&BigInt> for BigDecimal {
type Output = BigDecimal;

#[inline]
Expand All @@ -87,7 +87,7 @@ impl<'a> Mul<&'a BigInt> for BigDecimal {
}
}

impl<'a> Mul<BigInt> for &'a BigDecimal {
impl Mul<BigInt> for &BigDecimal {
type Output = BigDecimal;

#[inline]
Expand All @@ -97,7 +97,7 @@ impl<'a> Mul<BigInt> for &'a BigDecimal {
}
}

impl<'a, 'b> Mul<&'a BigInt> for &'b BigDecimal {
impl Mul<&BigInt> for &BigDecimal {
type Output = BigDecimal;

#[inline]
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Mul<BigDecimal> for BigInt {
}
}

impl<'a> Mul<BigDecimal> for &'a BigInt {
impl Mul<BigDecimal> for &BigInt {
type Output = BigDecimal;

#[inline]
Expand All @@ -147,7 +147,7 @@ impl<'a> Mul<BigDecimal> for &'a BigInt {
}
}

impl<'a, 'b> Mul<&'a BigDecimal> for &'b BigInt {
impl Mul<&BigDecimal> for &BigInt {
type Output = BigDecimal;

#[inline]
Expand All @@ -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]
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions src/impl_ops_rem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Rem<BigDecimal> for BigDecimal {
}
}

impl<'a> Rem<&'a BigDecimal> for BigDecimal {
impl Rem<&BigDecimal> for BigDecimal {
type Output = BigDecimal;

#[inline]
Expand All @@ -35,7 +35,7 @@ impl<'a> Rem<&'a BigDecimal> for BigDecimal {
}
}

impl<'a> Rem<BigDecimal> for &'a BigDecimal {
impl Rem<BigDecimal> for &BigDecimal {
type Output = BigDecimal;

#[inline]
Expand All @@ -55,7 +55,7 @@ impl<'a> Rem<BigDecimal> for &'a BigDecimal {
}
}

impl<'a, 'b> Rem<&'b BigDecimal> for &'a BigDecimal {
impl Rem<&BigDecimal> for &BigDecimal {
type Output = BigDecimal;

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/impl_trait_from_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};
}
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down Expand Up @@ -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());
}
}
Expand Down
1 change: 0 additions & 1 deletion src/with_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ mod stdlib {
slice,
str,
string,
i8,
f32,
f64,
};
Expand Down

0 comments on commit 477947b

Please # to comment.