Skip to content

Commit 68a6300

Browse files
authored
Clippy Fixes (#174)
* Clean up * Tweak
1 parent b02b0c2 commit 68a6300

File tree

10 files changed

+20
-25
lines changed

10 files changed

+20
-25
lines changed

src/boolean/and.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<F: PrimeField> Boolean<F> {
107107
}
108108
}
109109

110-
impl<'a, F: Field> BitAnd<Self> for &'a Boolean<F> {
110+
impl<F: Field> BitAnd<Self> for &Boolean<F> {
111111
type Output = Boolean<F>;
112112
/// Outputs `self & other`.
113113
///
@@ -142,16 +142,16 @@ impl<'a, F: Field> BitAnd<Self> for &'a Boolean<F> {
142142
}
143143
}
144144

145-
impl<'a, F: Field> BitAnd<&'a Self> for Boolean<F> {
145+
impl<F: Field> BitAnd<&Self> for Boolean<F> {
146146
type Output = Boolean<F>;
147147

148148
#[tracing::instrument(target = "gr1cs", skip(self, other))]
149149
fn bitand(self, other: &Self) -> Self::Output {
150-
self._and(&other).unwrap()
150+
self._and(other).unwrap()
151151
}
152152
}
153153

154-
impl<'a, F: Field> BitAnd<Boolean<F>> for &'a Boolean<F> {
154+
impl<F: Field> BitAnd<Boolean<F>> for &Boolean<F> {
155155
type Output = Boolean<F>;
156156

157157
#[tracing::instrument(target = "gr1cs", skip(self, other))]

src/fields/cubic_extension.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
};
77
use ark_ff::{
88
fields::{CubicExtField, Field},
9-
CubicExtConfig, Zero,
9+
AdditiveGroup, CubicExtConfig,
1010
};
1111
use ark_relations::gr1cs::{ConstraintSystemRef, Namespace, SynthesisError};
1212
use core::{borrow::Borrow, marker::PhantomData};
@@ -277,7 +277,7 @@ where
277277
self.cs(),
278278
|| {
279279
self.value()
280-
.map(|f| f.inverse().unwrap_or_else(CubicExtField::zero))
280+
.map(|f| f.inverse().unwrap_or(CubicExtField::ZERO))
281281
},
282282
mode,
283283
)?;

src/fields/emulated_fp/allocated_field_var.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<TargetF: PrimeField, BaseF: PrimeField> AllocatedEmulatedFpVar<TargetF, Bas
290290
#[tracing::instrument(target = "gr1cs")]
291291
pub fn inverse(&self) -> R1CSResult<Self> {
292292
let inverse = Self::new_witness(self.cs(), || {
293-
Ok(self.value()?.inverse().unwrap_or_else(TargetF::zero))
293+
Ok(self.value()?.inverse().unwrap_or(TargetF::ZERO))
294294
})?;
295295

296296
let actual_result = self.clone().mul(&inverse)?;

src/fields/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub trait FieldVar<F: Field, ConstraintF: PrimeField>:
191191
// and check that `result * d = self`.
192192
_ => {
193193
let result = Self::new_witness(ark_relations::ns!(cs, "self * d_inv"), || {
194-
Ok(self.value()? * &d.value()?.inverse().unwrap_or(F::zero()))
194+
Ok(self.value()? * &d.value()?.inverse().unwrap_or(F::ZERO))
195195
})?;
196196
result.mul_equals(d, self)?;
197197
Ok(result)

src/fields/quadratic_extension.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
};
77
use ark_ff::{
88
fields::{Field, QuadExtConfig, QuadExtField},
9-
Zero,
9+
AdditiveGroup,
1010
};
1111
use ark_relations::gr1cs::{ConstraintSystemRef, Namespace, SynthesisError};
1212
use core::{borrow::Borrow, marker::PhantomData};
@@ -285,7 +285,7 @@ where
285285
self.cs(),
286286
|| {
287287
self.value()
288-
.map(|f| f.inverse().unwrap_or_else(QuadExtField::zero))
288+
.map(|f| f.inverse().unwrap_or(QuadExtField::ZERO))
289289
},
290290
mode,
291291
)?;

src/groups/curves/short_weierstrass/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,8 @@ where
504504
&self,
505505
bits: impl Iterator<Item = &'a Boolean<BasePrimeField<P>>>,
506506
) -> Result<Self, SynthesisError> {
507-
if self.is_constant() {
508-
if self.value().unwrap().is_zero() {
509-
return Ok(self.clone());
510-
}
507+
if self.is_constant() && self.value().unwrap().is_zero() {
508+
return Ok(self.clone());
511509
}
512510
let self_affine = self.to_affine()?;
513511
let (x, y, infinity) = (self_affine.x, self_affine.y, self_affine.infinity);

src/uint/convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<const N: usize, F: Field, T: PrimUInt> UInt<N, T, F> {
1414
where
1515
F: PrimeField,
1616
{
17-
assert!(N <= F::MODULUS_BIT_SIZE as usize - 1);
17+
assert!(N < F::MODULUS_BIT_SIZE as usize);
1818

1919
Boolean::le_bits_to_fp(&self.bits)
2020
}

src/uint/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ impl<const N: usize, T: PrimUInt, F: Field> UInt<N, T, F> {
8383
let mut bits = [Boolean::FALSE; N];
8484
let mut bit_values = value;
8585

86-
for i in 0..N {
87-
bits[i] = Boolean::constant((bit_values & T::one()) == T::one());
88-
bit_values = bit_values >> 1u8;
86+
for bit in &mut bits {
87+
*bit = Boolean::constant((bit_values & T::one()) == T::one());
88+
bit_values >>= 1u8;
8989
}
9090

9191
Self {

src/uint/prim_uint.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use core::{
2-
ops::{Shl, ShlAssign, Shr, ShrAssign},
3-
usize,
4-
};
1+
use core::ops::{Shl, ShlAssign, Shr, ShrAssign};
52

63
#[doc(hidden)]
74
// Adapted from <https://github.com/rust-num/num-traits/pull/224>

src/uint/xor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<&'a Self> for UInt<N, T,
6060
}
6161
}
6262

63-
impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<UInt<N, T, F>> for &'a UInt<N, T, F> {
63+
impl<const N: usize, T: PrimUInt, F: Field> BitXor<UInt<N, T, F>> for &UInt<N, T, F> {
6464
type Output = UInt<N, T, F>;
6565

6666
#[tracing::instrument(target = "gr1cs", skip(self, other))]
@@ -78,7 +78,7 @@ impl<const N: usize, T: PrimUInt, F: Field> BitXor<Self> for UInt<N, T, F> {
7878
}
7979
}
8080

81-
impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<T> for UInt<N, T, F> {
81+
impl<const N: usize, T: PrimUInt, F: Field> BitXor<T> for UInt<N, T, F> {
8282
type Output = UInt<N, T, F>;
8383

8484
#[tracing::instrument(target = "gr1cs", skip(self, other))]
@@ -105,7 +105,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<&'a T> for &'a UInt<N, T,
105105
}
106106
}
107107

108-
impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<T> for &'a UInt<N, T, F> {
108+
impl<const N: usize, T: PrimUInt, F: Field> BitXor<T> for &UInt<N, T, F> {
109109
type Output = UInt<N, T, F>;
110110

111111
#[tracing::instrument(target = "gr1cs", skip(self, other))]

0 commit comments

Comments
 (0)