Skip to content

Commit d782512

Browse files
Merge #176
176: silenced a bunch of misleading Clippy warnings r=cuviper a=BartMassey * There were a bunch of code quality Clippy warnings that didn't apply for various reasons. * There was an ok_or() that could have been an ok_or_else() that Clippy caught. Turns out it's for a ZST, so doesn't matter, but was "fixed" anyway to silence Clippy. This will hopefully make "cargo clippy" more useful for the next person. Co-authored-by: Bart Massey <[email protected]>
2 parents 92b8f48 + a2b160c commit d782512

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/algorithms.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ fn bigint_from_slice(slice: &[BigDigit]) -> BigInt {
349349

350350
/// Three argument multiply accumulate:
351351
/// acc += b * c
352+
#[allow(clippy::many_single_char_names)]
352353
fn mac3(acc: &mut [BigDigit], b: &[BigDigit], c: &[BigDigit]) {
353354
let (x, y) = if b.len() < c.len() { (b, c) } else { (c, b) };
354355

src/bigint.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2707,7 +2707,9 @@ impl TryFrom<&BigInt> for BigUint {
27072707

27082708
#[inline]
27092709
fn try_from(value: &BigInt) -> Result<BigUint, TryFromBigIntError<()>> {
2710-
value.to_biguint().ok_or(TryFromBigIntError::new(()))
2710+
value
2711+
.to_biguint()
2712+
.ok_or_else(|| TryFromBigIntError::new(()))
27112713
}
27122714
}
27132715

src/biguint.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,12 @@ impl Roots for BigUint {
18141814
fn high_bits_to_u64(v: &BigUint) -> u64 {
18151815
match v.data.len() {
18161816
0 => 0,
1817-
1 => u64::from(v.data[0]),
1817+
1 => {
1818+
// XXX Conversion is useless if already 64-bit.
1819+
#[allow(clippy::useless_conversion)]
1820+
let v0 = u64::from(v.data[0]);
1821+
v0
1822+
}
18181823
_ => {
18191824
let mut bits = v.bits();
18201825
let mut ret = 0u64;
@@ -1827,7 +1832,10 @@ fn high_bits_to_u64(v: &BigUint) -> u64 {
18271832
if bits_want != 64 {
18281833
ret <<= bits_want;
18291834
}
1830-
ret |= u64::from(*d) >> (digit_bits - bits_want);
1835+
// XXX Conversion is useless if already 64-bit.
1836+
#[allow(clippy::useless_conversion)]
1837+
let d0 = u64::from(*d) >> (digit_bits - bits_want);
1838+
ret |= d0;
18311839
ret_bits += bits_want;
18321840
bits -= bits_want;
18331841

@@ -1852,6 +1860,7 @@ impl ToPrimitive for BigUint {
18521860
self.to_u128().as_ref().and_then(u128::to_i128)
18531861
}
18541862

1863+
#[allow(clippy::useless_conversion)]
18551864
#[inline]
18561865
fn to_u64(&self) -> Option<u64> {
18571866
let mut ret: u64 = 0;
@@ -1862,6 +1871,7 @@ impl ToPrimitive for BigUint {
18621871
return None;
18631872
}
18641873

1874+
// XXX Conversion is useless if already 64-bit.
18651875
ret += u64::from(*i) << bits;
18661876
bits += big_digit::BITS;
18671877
}

src/monty.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl MontyReducer {
4141
/// In the terminology of that paper, this is an "Almost Montgomery Multiplication":
4242
/// x and y are required to satisfy 0 <= z < 2**(n*_W) and then the result
4343
/// z is guaranteed to satisfy 0 <= z < 2**(n*_W), but it may not be < m.
44+
#[allow(clippy::many_single_char_names)]
4445
fn montgomery(x: &BigUint, y: &BigUint, m: &BigUint, k: BigDigit, n: usize) -> BigUint {
4546
// This code assumes x, y, m are all the same length, n.
4647
// (required by addMulVVW and the for loop).
@@ -131,6 +132,7 @@ fn mul_add_www(x: BigDigit, y: BigDigit, c: BigDigit) -> (BigDigit, BigDigit) {
131132
}
132133

133134
/// Calculates x ** y mod m using a fixed, 4-bit window.
135+
#[allow(clippy::many_single_char_names)]
134136
pub(crate) fn monty_modpow(x: &BigUint, y: &BigUint, m: &BigUint) -> BigUint {
135137
assert!(m.data[0] & 1 == 1);
136138
let mr = MontyReducer::new(m);

0 commit comments

Comments
 (0)