diff --git a/src/lexical/algorithm.rs b/src/lexical/algorithm.rs index a5c1afc..69ac588 100644 --- a/src/lexical/algorithm.rs +++ b/src/lexical/algorithm.rs @@ -179,9 +179,9 @@ where let b = fp.into_downward_float::(); if b.is_special() { // We have a non-finite number, we get to leave early. - return b; + b } else { - return bhcomp(b, integer, fraction, exponent); + bhcomp(b, integer, fraction, exponent) } } @@ -197,7 +197,7 @@ mod tests { // valid let mantissa = (1 << f32::MANTISSA_SIZE) - 1; let (min_exp, max_exp) = f32::exponent_limit(); - for exp in min_exp..max_exp + 1 { + for exp in min_exp..=max_exp { let f = fast_path::(mantissa, exp); assert!(f.is_some(), "should be valid {:?}.", (mantissa, exp)); } @@ -236,7 +236,7 @@ mod tests { // valid let mantissa = (1 << f64::MANTISSA_SIZE) - 1; let (min_exp, max_exp) = f64::exponent_limit(); - for exp in min_exp..max_exp + 1 { + for exp in min_exp..=max_exp { let f = fast_path::(mantissa, exp); assert!(f.is_some(), "should be valid {:?}.", (mantissa, exp)); } diff --git a/src/lexical/bignum.rs b/src/lexical/bignum.rs index af5a1f7..d419420 100644 --- a/src/lexical/bignum.rs +++ b/src/lexical/bignum.rs @@ -23,12 +23,12 @@ impl Default for Bigint { impl Math for Bigint { #[inline] - fn data<'a>(&'a self) -> &'a Vec { + fn data(&self) -> &Vec { &self.data } #[inline] - fn data_mut<'a>(&'a mut self) -> &'a mut Vec { + fn data_mut(&mut self) -> &mut Vec { &mut self.data } } diff --git a/src/lexical/digit.rs b/src/lexical/digit.rs index 2d3b337..f8d3f9b 100644 --- a/src/lexical/digit.rs +++ b/src/lexical/digit.rs @@ -9,5 +9,5 @@ pub(crate) fn to_digit(c: u8) -> Option { // Add digit to mantissa. #[inline] pub(crate) fn add_digit(value: u64, digit: u32) -> Option { - return value.checked_mul(10)?.checked_add(digit as u64); + value.checked_mul(10)?.checked_add(digit as u64) } diff --git a/src/lexical/errors.rs b/src/lexical/errors.rs index c53ff39..93eeae2 100644 --- a/src/lexical/errors.rs +++ b/src/lexical/errors.rs @@ -68,9 +68,10 @@ impl FloatErrors for u64 { let denormal_exp = bias - 63; // This is always a valid u32, since (denormal_exp - fp.exp) // will always be positive and the significand size is {23, 52}. - let extrabits = match fp.exp <= denormal_exp { - true => 64 - F::MANTISSA_SIZE + denormal_exp - fp.exp, - false => 63 - F::MANTISSA_SIZE, + let extrabits = if fp.exp <= denormal_exp { + 64 - F::MANTISSA_SIZE + denormal_exp - fp.exp + } else { + 63 - F::MANTISSA_SIZE }; // Our logic is as follows: we want to determine if the actual diff --git a/src/lexical/float.rs b/src/lexical/float.rs index dddcfac..eb35482 100644 --- a/src/lexical/float.rs +++ b/src/lexical/float.rs @@ -389,7 +389,7 @@ mod tests { 1e-40, 2e-40, 1e-35, 2e-35, 1e-30, 2e-30, 1e-25, 2e-25, 1e-20, 2e-20, 1e-15, 2e-15, 1e-10, 2e-10, 1e-5, 2e-5, 1.0, 2.0, 1e5, 2e5, 1e10, 2e10, 1e15, 2e15, 1e20, 2e20, ]; - for value in values.iter() { + for value in &values { assert_normalized_eq( ExtendedFloat::from_float(*value), ExtendedFloat::from_float(*value as f64), @@ -515,7 +515,7 @@ mod tests { assert_eq!(x.into_float::(), f32::INFINITY); // Integers. - for int in INTEGERS.iter() { + for int in &INTEGERS { let fp = ExtendedFloat { mant: *int, exp: 0 }; assert_eq!(fp.into_float::(), *int as f32, "{:?} as f32", *int); } @@ -656,7 +656,7 @@ mod tests { assert_eq!(x.into_float::(), 5e-324); // Integers. - for int in INTEGERS.iter() { + for int in &INTEGERS { let fp = ExtendedFloat { mant: *int, exp: 0 }; assert_eq!(fp.into_float::(), *int as f64, "{:?} as f64", *int); } diff --git a/src/lexical/large_powers64.rs b/src/lexical/large_powers64.rs index a68356e..3e679e6 100644 --- a/src/lexical/large_powers64.rs +++ b/src/lexical/large_powers64.rs @@ -617,7 +617,7 @@ const POW5_14: [u64; 298] = [ 9640, ]; -pub(crate) const POW5: [&'static [u64]; 14] = [ +pub(crate) const POW5: [&[u64]; 14] = [ &POW5_1, &POW5_2, &POW5_3, &POW5_4, &POW5_5, &POW5_6, &POW5_7, &POW5_8, &POW5_9, &POW5_10, &POW5_11, &POW5_12, &POW5_13, &POW5_14, ]; diff --git a/src/lexical/math.rs b/src/lexical/math.rs index 4516c18..2705541 100644 --- a/src/lexical/math.rs +++ b/src/lexical/math.rs @@ -576,8 +576,7 @@ mod small { // minus leading zero bits. let nlz = leading_zeros(x); bits.checked_mul(x.len()) - .map(|v| v - nlz) - .unwrap_or(usize::max_value()) + .map_or_else(usize::max_value, |v| v - nlz) } // SHL @@ -668,9 +667,9 @@ mod large { #[inline] pub fn compare(x: &[Limb], y: &[Limb]) -> cmp::Ordering { if x.len() > y.len() { - return cmp::Ordering::Greater; + cmp::Ordering::Greater } else if x.len() < y.len() { - return cmp::Ordering::Less; + cmp::Ordering::Less } else { let iter = x.iter().rev().zip(y.iter().rev()); for (&xi, &yi) in iter { @@ -681,7 +680,7 @@ mod large { } } // Equal case. - return cmp::Ordering::Equal; + cmp::Ordering::Equal } } @@ -809,7 +808,7 @@ mod large { /// Split two buffers into halfway, into (lo, hi). #[inline] - pub fn karatsuba_split<'a>(z: &'a [Limb], m: usize) -> (&'a [Limb], &'a [Limb]) { + pub fn karatsuba_split(z: &[Limb], m: usize) -> (&[Limb], &[Limb]) { (&z[..m], &z[m..]) } @@ -862,7 +861,7 @@ mod large { // two numbers, except we're using splits on `y`, and the intermediate // step is a Karatsuba multiplication. let mut start = 0; - while y.len() != 0 { + while !y.is_empty() { let m = x.len().min(y.len()); let (yl, yh) = karatsuba_split(y, m); let prod = karatsuba_mul(x, yl); @@ -912,10 +911,10 @@ pub(crate) trait Math: Clone + Sized + Default { // DATA /// Get access to the underlying data - fn data<'a>(&'a self) -> &'a Vec; + fn data(&self) -> &Vec; /// Get access to the underlying data - fn data_mut<'a>(&'a mut self) -> &'a mut Vec; + fn data_mut(&mut self) -> &mut Vec; // RELATIVE OPERATIONS @@ -1019,12 +1018,12 @@ mod tests { impl Math for Bigint { #[inline] - fn data<'a>(&'a self) -> &'a Vec { + fn data(&self) -> &Vec { &self.data } #[inline] - fn data_mut<'a>(&'a mut self) -> &'a mut Vec { + fn data_mut(&mut self) -> &mut Vec { &mut self.data } } diff --git a/src/lexical/rounding.rs b/src/lexical/rounding.rs index 29b5946..40dec7a 100644 --- a/src/lexical/rounding.rs +++ b/src/lexical/rounding.rs @@ -22,9 +22,10 @@ pub(crate) fn lower_n_mask(n: u64) -> u64 { let bits: u64 = mem::size_of::() as u64 * 8; debug_assert!(n <= bits, "lower_n_mask() overflow in shl."); - match n == bits { - true => u64::max_value(), - false => (1 << n) - 1, + if n == bits { + u64::max_value() + } else { + (1 << n) - 1 } } @@ -34,9 +35,10 @@ pub(crate) fn lower_n_halfway(n: u64) -> u64 { let bits: u64 = mem::size_of::() as u64 * 8; debug_assert!(n <= bits, "lower_n_halfway() overflow in shl."); - match n == 0 { - true => 0, - false => nth_bit(n - 1), + if n == 0 { + 0 + } else { + nth_bit(n - 1) } } diff --git a/src/lexical/shift.rs b/src/lexical/shift.rs index 9446d71..344e5c0 100644 --- a/src/lexical/shift.rs +++ b/src/lexical/shift.rs @@ -25,9 +25,10 @@ pub(crate) fn overflowing_shr(fp: &mut ExtendedFloat, shift: i32) { "overflowing_shr() overflow in shift right." ); - fp.mant = match shift as u64 == bits { - true => 0, - false => fp.mant >> shift, + fp.mant = if shift as u64 == bits { + 0 + } else { + fp.mant >> shift }; fp.exp += shift; } diff --git a/src/lexical/slice.rs b/src/lexical/slice.rs index 45f9508..f1695dc 100644 --- a/src/lexical/slice.rs +++ b/src/lexical/slice.rs @@ -108,7 +108,7 @@ pub trait Slice { /// Create a reverse view of the vector for indexing. #[inline] - fn rview<'a>(&'a self) -> ReverseView<'a, T> { + fn rview(&self) -> ReverseView { ReverseView { inner: self.as_slice(), } diff --git a/src/lib.rs b/src/lib.rs index a1e53ab..a6bbe32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -304,8 +304,11 @@ #![deny(clippy::all, clippy::pedantic)] // Ignored clippy lints #![allow( + clippy::comparison_chain, clippy::deprecated_cfg_attr, clippy::doc_markdown, + clippy::excessive_precision, + clippy::float_cmp, clippy::match_single_binding, clippy::needless_doctest_main, clippy::transmute_ptr_to_ptr @@ -315,12 +318,15 @@ // Deserializer::from_str, into_iter clippy::should_implement_trait, // integer and float ser/de requires these sorts of casts + clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_precision_loss, clippy::cast_sign_loss, // correctly used clippy::enum_glob_use, + clippy::if_not_else, clippy::integer_division, + clippy::similar_names, clippy::wildcard_imports, // things are often more readable this way clippy::cast_lossless, @@ -328,6 +334,8 @@ clippy::shadow_unrelated, clippy::single_match_else, clippy::too_many_lines, + clippy::unreadable_literal, + clippy::unseparated_literal_suffix, clippy::use_self, clippy::zero_prefixed_literal, // we support older compilers