Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply clippy suggestions #943

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ec/src/hashing/curve_maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ pub fn parity<F: Field>(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())
}
2 changes: 1 addition & 1 deletion ec/src/models/bn/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<P: BnConfig> From<G2Affine<P>> for G2Prepared<P> {
match bit {
1 => ell_coeffs.push(r.add_in_place(&q)),
-1 => ell_coeffs.push(r.add_in_place(&neg_q)),
_ => continue,
_ => {},
}
}

Expand Down
2 changes: 1 addition & 1 deletion ec/src/models/bw6/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<P: BW6Config> From<G2Affine<P>> for G2Prepared<P> {
match bit {
1 => ell_coeffs_2.push(r.add_in_place(&qu)),
-1 => ell_coeffs_2.push(r.add_in_place(&neg_qu)),
_ => continue,
_ => {},
}
}

Expand Down
1 change: 0 additions & 1 deletion ec/src/models/short_weierstrass/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ impl<P: SWCurveConfig> AffineRepr for Affine<P> {

/// 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)
}
Expand Down
1 change: 0 additions & 1 deletion ec/src/models/twisted_edwards/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ impl<P: TECurveConfig> AffineRepr for Affine<P> {

/// 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)
}
Expand Down
2 changes: 1 addition & 1 deletion ff/src/fields/field_hashers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ const fn get_len_per_elem<F: Field, const SEC_PARAM: usize>() -> 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
}
1 change: 0 additions & 1 deletion ff/src/fields/models/fp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,6 @@ impl<P: FpConfig<N>, const N: usize> Display for Fp<P, N> {
impl<P: FpConfig<N>, const N: usize> Neg for Fp<P, N> {
type Output = Self;
#[inline]
#[must_use]
fn neg(mut self) -> Self {
P::neg_in_place(&mut self);
self
Expand Down
1 change: 0 additions & 1 deletion ff/src/fields/models/quadratic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ impl<P: QuadExtConfig> From<bool> for QuadExtField<P> {
impl<P: QuadExtConfig> Neg for QuadExtField<P> {
type Output = Self;
#[inline]
#[must_use]
fn neg(mut self) -> Self {
self.c0.neg_in_place();
self.c1.neg_in_place();
Expand Down
2 changes: 1 addition & 1 deletion ff/src/fields/prime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion poly/src/domain/radix2/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<F: FftField> Radix2EvaluationDomain<F> {

// 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
Expand Down
4 changes: 2 additions & 2 deletions poly/src/evaluations/multivariate/multilinear/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl<F: Field> MultilinearExtension<F> for SparseMultilinearExtension<F> {
self.evaluations
.iter()
.map(|(&i, &v)| evaluations[i] = v)
.last();
.next_back();
evaluations
}
}
Expand Down Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion poly/src/polynomial/multivariate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions poly/src/polynomial/univariate/dense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<F: Field> Polynomial<F> for DensePolynomial<F> {
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
}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<F: FftField> DensePolynomial<F> {

impl<F: Field> DensePolynomial<F> {
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();
}
}
Expand Down
4 changes: 2 additions & 2 deletions poly/src/polynomial/univariate/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<F: Field> Polynomial<F> for SparsePolynomial<F> {
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
}
}
Expand Down Expand Up @@ -240,7 +240,7 @@ impl<F: Field> SparsePolynomial<F> {
/// 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.
Expand Down
2 changes: 1 addition & 1 deletion serialize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion test-templates/src/glv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn glv_scalar_decomposition<P: GLVConfig>() {
}

// 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",
Expand Down
Loading