From 11b3c66d54684a2b1047bfbdd9059c7cdcf95914 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Tue, 25 Feb 2025 16:29:12 +0100 Subject: [PATCH] apply clippy suggestions --- ec/src/hashing/curve_maps/mod.rs | 2 +- ec/src/models/bn/g2.rs | 2 +- ec/src/models/bw6/g2.rs | 2 +- ec/src/models/short_weierstrass/affine.rs | 1 - ec/src/models/twisted_edwards/affine.rs | 1 - ff/src/fields/field_hashers/mod.rs | 2 +- ff/src/fields/models/fp/mod.rs | 1 - ff/src/fields/models/quadratic_extension.rs | 1 - ff/src/fields/prime.rs | 2 +- poly/src/domain/radix2/fft.rs | 2 +- poly/src/evaluations/multivariate/multilinear/sparse.rs | 4 ++-- poly/src/polynomial/multivariate/mod.rs | 2 +- poly/src/polynomial/univariate/dense.rs | 4 ++-- poly/src/polynomial/univariate/sparse.rs | 4 ++-- serialize/src/lib.rs | 2 +- test-templates/src/glv.rs | 2 +- 16 files changed, 15 insertions(+), 19 deletions(-) diff --git a/ec/src/hashing/curve_maps/mod.rs b/ec/src/hashing/curve_maps/mod.rs index 319e8e9ef..8dd24b4a6 100644 --- a/ec/src/hashing/curve_maps/mod.rs +++ b/ec/src/hashing/curve_maps/mod.rs @@ -10,5 +10,5 @@ pub fn parity(element: &F) -> bool { element .to_base_prime_field_elements() .find(|&x| !x.is_zero()) - .map_or(false, |x| x.into_bigint().is_odd()) + .is_some_and(|x| x.into_bigint().is_odd()) } diff --git a/ec/src/models/bn/g2.rs b/ec/src/models/bn/g2.rs index 08bd389ab..f7026ad93 100644 --- a/ec/src/models/bn/g2.rs +++ b/ec/src/models/bn/g2.rs @@ -120,7 +120,7 @@ impl From> for G2Prepared

{ match bit { 1 => ell_coeffs.push(r.add_in_place(&q)), -1 => ell_coeffs.push(r.add_in_place(&neg_q)), - _ => continue, + _ => {}, } } diff --git a/ec/src/models/bw6/g2.rs b/ec/src/models/bw6/g2.rs index 9b8471e85..d5980526d 100644 --- a/ec/src/models/bw6/g2.rs +++ b/ec/src/models/bw6/g2.rs @@ -101,7 +101,7 @@ impl From> for G2Prepared

{ match bit { 1 => ell_coeffs_2.push(r.add_in_place(&qu)), -1 => ell_coeffs_2.push(r.add_in_place(&neg_qu)), - _ => continue, + _ => {}, } } diff --git a/ec/src/models/short_weierstrass/affine.rs b/ec/src/models/short_weierstrass/affine.rs index 75d0e1b3d..63b179eec 100644 --- a/ec/src/models/short_weierstrass/affine.rs +++ b/ec/src/models/short_weierstrass/affine.rs @@ -238,7 +238,6 @@ impl AffineRepr for Affine

{ /// Multiplies this element by the cofactor and output the /// resulting projective element. - #[must_use] fn mul_by_cofactor_to_group(&self) -> Self::Group { P::mul_affine(self, Self::Config::COFACTOR) } diff --git a/ec/src/models/twisted_edwards/affine.rs b/ec/src/models/twisted_edwards/affine.rs index 3481b05c5..48670f4c4 100644 --- a/ec/src/models/twisted_edwards/affine.rs +++ b/ec/src/models/twisted_edwards/affine.rs @@ -184,7 +184,6 @@ impl AffineRepr for Affine

{ /// Multiplies this element by the cofactor and output the /// resulting projective element. - #[must_use] fn mul_by_cofactor_to_group(&self) -> Self::Group { P::mul_affine(self, Self::Config::COFACTOR) } diff --git a/ff/src/fields/field_hashers/mod.rs b/ff/src/fields/field_hashers/mod.rs index f6b764809..7a6ff0ed7 100644 --- a/ff/src/fields/field_hashers/mod.rs +++ b/ff/src/fields/field_hashers/mod.rs @@ -113,6 +113,6 @@ const fn get_len_per_elem() -> usize { let base_field_size_with_security_padding_in_bits = base_field_size_in_bits + SEC_PARAM; // ceil( (ceil(log(p)) + security_parameter) / 8) let bytes_per_base_field_elem = - ((base_field_size_with_security_padding_in_bits + 7) / 8) as u64; + base_field_size_with_security_padding_in_bits.div_ceil(8) as u64; bytes_per_base_field_elem as usize } diff --git a/ff/src/fields/models/fp/mod.rs b/ff/src/fields/models/fp/mod.rs index 87ceda04e..32b74ee1d 100644 --- a/ff/src/fields/models/fp/mod.rs +++ b/ff/src/fields/models/fp/mod.rs @@ -677,7 +677,6 @@ impl, const N: usize> Display for Fp { impl, const N: usize> Neg for Fp { type Output = Self; #[inline] - #[must_use] fn neg(mut self) -> Self { P::neg_in_place(&mut self); self diff --git a/ff/src/fields/models/quadratic_extension.rs b/ff/src/fields/models/quadratic_extension.rs index 914ea3b4a..ec901c5b6 100644 --- a/ff/src/fields/models/quadratic_extension.rs +++ b/ff/src/fields/models/quadratic_extension.rs @@ -570,7 +570,6 @@ impl From for QuadExtField

{ impl Neg for QuadExtField

{ type Output = Self; #[inline] - #[must_use] fn neg(mut self) -> Self { self.c0.neg_in_place(); self.c1.neg_in_place(); diff --git a/ff/src/fields/prime.rs b/ff/src/fields/prime.rs index 43b331b65..8815be2c2 100644 --- a/ff/src/fields/prime.rs +++ b/ff/src/fields/prime.rs @@ -70,7 +70,7 @@ pub trait PrimeField: /// If the integer represented by `bytes` is larger than the modulus `p`, this method /// performs the appropriate reduction. fn from_le_bytes_mod_order(bytes: &[u8]) -> Self { - let num_modulus_bytes = ((Self::MODULUS_BIT_SIZE + 7) / 8) as usize; + let num_modulus_bytes = Self::MODULUS_BIT_SIZE.div_ceil(8) as usize; let num_bytes_to_directly_convert = min(num_modulus_bytes - 1, bytes.len()); // Copy the leading little-endian bytes directly into a field element. // The number of bytes directly converted must be less than the diff --git a/poly/src/domain/radix2/fft.rs b/poly/src/domain/radix2/fft.rs index 94fdff536..5e55fed23 100644 --- a/poly/src/domain/radix2/fft.rs +++ b/poly/src/domain/radix2/fft.rs @@ -167,7 +167,7 @@ impl Radix2EvaluationDomain { // recursive case: // 1. split log_powers in half - let (lr_lo, lr_hi) = log_powers.split_at((1 + log_powers.len()) / 2); + let (lr_lo, lr_hi) = log_powers.split_at(log_powers.len().div_ceil(2)); let mut scr_lo = vec![F::default(); 1 << lr_lo.len()]; let mut scr_hi = vec![F::default(); 1 << lr_hi.len()]; // 2. compute each half individually diff --git a/poly/src/evaluations/multivariate/multilinear/sparse.rs b/poly/src/evaluations/multivariate/multilinear/sparse.rs index ea8f05319..5b8f508a1 100644 --- a/poly/src/evaluations/multivariate/multilinear/sparse.rs +++ b/poly/src/evaluations/multivariate/multilinear/sparse.rs @@ -194,7 +194,7 @@ impl MultilinearExtension for SparseMultilinearExtension { self.evaluations .iter() .map(|(&i, &v)| evaluations[i] = v) - .last(); + .next_back(); evaluations } } @@ -490,7 +490,7 @@ mod tests { points .into_iter() .map(|(i, v)| assert_eq!(poly[i], v)) - .last(); + .next_back(); assert_eq!(poly[0], Fr::zero()); assert_eq!(poly[1], Fr::zero()); } diff --git a/poly/src/polynomial/multivariate/mod.rs b/poly/src/polynomial/multivariate/mod.rs index e4ea9bb62..bdeaf395b 100644 --- a/poly/src/polynomial/multivariate/mod.rs +++ b/poly/src/polynomial/multivariate/mod.rs @@ -104,7 +104,7 @@ impl Term for SparseTerm { /// Returns whether `self` is a constant fn is_constant(&self) -> bool { - self.len() == 0 || self.degree() == 0 + self.is_empty() || self.degree() == 0 } /// Evaluates `self` at the given `point` in the field. diff --git a/poly/src/polynomial/univariate/dense.rs b/poly/src/polynomial/univariate/dense.rs index 52d024c70..fcd81192d 100644 --- a/poly/src/polynomial/univariate/dense.rs +++ b/poly/src/polynomial/univariate/dense.rs @@ -32,7 +32,7 @@ impl Polynomial for DensePolynomial { if self.is_zero() { 0 } else { - assert!(self.coeffs.last().map_or(false, |coeff| !coeff.is_zero())); + assert!(self.coeffs.last().is_some_and(|coeff| !coeff.is_zero())); self.coeffs.len() - 1 } } @@ -211,7 +211,7 @@ impl DensePolynomial { impl DensePolynomial { fn truncate_leading_zeros(&mut self) { - while self.coeffs.last().map_or(false, |c| c.is_zero()) { + while self.coeffs.last().is_some_and(|c| c.is_zero()) { self.coeffs.pop(); } } diff --git a/poly/src/polynomial/univariate/sparse.rs b/poly/src/polynomial/univariate/sparse.rs index 9f71554ef..b8d606aaf 100644 --- a/poly/src/polynomial/univariate/sparse.rs +++ b/poly/src/polynomial/univariate/sparse.rs @@ -63,7 +63,7 @@ impl Polynomial for SparsePolynomial { if self.is_zero() { 0 } else { - assert!(self.coeffs.last().map_or(false, |(_, c)| !c.is_zero())); + assert!(self.coeffs.last().is_some_and(|(_, c)| !c.is_zero())); self.coeffs.last().unwrap().0 } } @@ -240,7 +240,7 @@ impl SparsePolynomial { /// of the same degree are ignored. pub fn from_coefficients_vec(mut coeffs: Vec<(usize, F)>) -> Self { // While there are zeros at the end of the coefficient vector, pop them off. - while coeffs.last().map_or(false, |(_, c)| c.is_zero()) { + while coeffs.last().is_some_and(|(_, c)| c.is_zero()) { coeffs.pop(); } // Ensure that coeffs are in ascending order. diff --git a/serialize/src/lib.rs b/serialize/src/lib.rs index 24a8c6182..4c0b41ce0 100644 --- a/serialize/src/lib.rs +++ b/serialize/src/lib.rs @@ -241,5 +241,5 @@ pub const fn buffer_bit_byte_size(modulus_bits: usize) -> (usize, usize) { /// into the number of bytes required to represent it. #[inline] pub const fn buffer_byte_size(modulus_bits: usize) -> usize { - (modulus_bits + 7) / 8 + modulus_bits.div_ceil(8) } diff --git a/test-templates/src/glv.rs b/test-templates/src/glv.rs index 9c343a73f..d67104745 100644 --- a/test-templates/src/glv.rs +++ b/test-templates/src/glv.rs @@ -28,7 +28,7 @@ pub fn glv_scalar_decomposition() { } // check if k1 and k2 are indeed small. - let expected_max_bits = (P::ScalarField::MODULUS_BIT_SIZE + 1) / 2; + let expected_max_bits = P::ScalarField::MODULUS_BIT_SIZE.div_ceil(2); assert!( k1.into_bigint().num_bits() <= expected_max_bits, "k1 has {} bits",