Skip to content

Commit

Permalink
Merge #278
Browse files Browse the repository at this point in the history
278: Clippy fixes r=cuviper a=waywardmonkeys

This fixes (or suppresses) all clippy warnings in the lib target. (It doesn't help for the test target.)

Co-authored-by: Bruce Mitchener <bruce.mitchener@gmail.com>
  • Loading branch information
bors[bot] and waywardmonkeys committed Aug 22, 2023
2 parents 9134523 + a87619d commit 2cea7f4
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/bigint/convert.rs
Expand Up @@ -389,7 +389,7 @@ pub(super) fn from_signed_bytes_be(digits: &[u8]) -> BigInt {
// two's-complement the content to retrieve the magnitude
let mut digits = Vec::from(digits);
twos_complement_be(&mut digits);
BigInt::from_biguint(sign, BigUint::from_bytes_be(&*digits))
BigInt::from_biguint(sign, BigUint::from_bytes_be(&digits))
} else {
BigInt::from_biguint(sign, BigUint::from_bytes_be(digits))
}
Expand All @@ -407,7 +407,7 @@ pub(super) fn from_signed_bytes_le(digits: &[u8]) -> BigInt {
// two's-complement the content to retrieve the magnitude
let mut digits = Vec::from(digits);
twos_complement_le(&mut digits);
BigInt::from_biguint(sign, BigUint::from_bytes_le(&*digits))
BigInt::from_biguint(sign, BigUint::from_bytes_le(&digits))
} else {
BigInt::from_biguint(sign, BigUint::from_bytes_le(digits))
}
Expand Down
2 changes: 1 addition & 1 deletion src/biguint.rs
Expand Up @@ -589,7 +589,7 @@ impl BigUint {
} else {
let mut v = bytes.to_vec();
v.reverse();
BigUint::from_bytes_le(&*v)
BigUint::from_bytes_le(&v)
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/biguint/convert.rs
@@ -1,3 +1,6 @@
// This uses stdlib features higher than the MSRV
#![allow(clippy::manual_range_contains)] // 1.35

use super::{biguint_from_vec, BigUint, ToBigUint};

use super::addition::add2;
Expand Down
4 changes: 2 additions & 2 deletions src/biguint/monty.rs
Expand Up @@ -78,8 +78,8 @@ fn montgomery(x: &BigUint, y: &BigUint, m: &BigUint, k: BigDigit, n: usize) -> B
z.data = z.data[n..].to_vec();
} else {
{
let (mut first, second) = z.data.split_at_mut(n);
sub_vv(&mut first, &second, &m.data);
let (first, second) = z.data.split_at_mut(n);
sub_vv(first, second, &m.data);
}
z.data = z.data[..n].to_vec();
}
Expand Down
10 changes: 5 additions & 5 deletions src/biguint/power.rs
Expand Up @@ -225,27 +225,27 @@ fn test_plain_modpow() {
let exp = vec![0, 0b1];
assert_eq!(
two.pow(0b1_00000000_u32) % &modulus,
plain_modpow(&two, &exp, &modulus)
plain_modpow(two, &exp, &modulus)
);
let exp = vec![0, 0b10];
assert_eq!(
two.pow(0b10_00000000_u32) % &modulus,
plain_modpow(&two, &exp, &modulus)
plain_modpow(two, &exp, &modulus)
);
let exp = vec![0, 0b110010];
assert_eq!(
two.pow(0b110010_00000000_u32) % &modulus,
plain_modpow(&two, &exp, &modulus)
plain_modpow(two, &exp, &modulus)
);
let exp = vec![0b1, 0b1];
assert_eq!(
two.pow(0b1_00000001_u32) % &modulus,
plain_modpow(&two, &exp, &modulus)
plain_modpow(two, &exp, &modulus)
);
let exp = vec![0b1100, 0, 0b1];
assert_eq!(
two.pow(0b1_00000000_00001100_u32) % &modulus,
plain_modpow(&two, &exp, &modulus)
plain_modpow(two, &exp, &modulus)
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/biguint/shift.rs
Expand Up @@ -35,7 +35,7 @@ fn biguint_shl2(n: Cow<'_, BigUint>, digits: usize, shift: u8) -> BigUint {

if shift > 0 {
let mut carry = 0;
let carry_shift = big_digit::BITS as u8 - shift;
let carry_shift = big_digit::BITS - shift;
for elem in data[digits..].iter_mut() {
let new_carry = *elem >> carry_shift;
*elem = (*elem << shift) | carry;
Expand Down Expand Up @@ -79,7 +79,7 @@ fn biguint_shr2(n: Cow<'_, BigUint>, digits: usize, shift: u8) -> BigUint {

if shift > 0 {
let mut borrow = 0;
let borrow_shift = big_digit::BITS as u8 - shift;
let borrow_shift = big_digit::BITS - shift;
for elem in data.iter_mut().rev() {
let new_borrow = *elem << borrow_shift;
*elem = (*elem >> shift) | borrow;
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Expand Up @@ -94,7 +94,7 @@ extern crate std;
#[cfg(feature = "std")]
mod std_alloc {
pub(crate) use std::borrow::Cow;
#[cfg(any(feature = "quickcheck"))]
#[cfg(feature = "quickcheck")]
pub(crate) use std::boxed::Box;
pub(crate) use std::string::String;
pub(crate) use std::vec::Vec;
Expand All @@ -107,7 +107,7 @@ extern crate alloc;
#[cfg(not(feature = "std"))]
mod std_alloc {
pub(crate) use alloc::borrow::Cow;
#[cfg(any(feature = "quickcheck"))]
#[cfg(feature = "quickcheck")]
pub(crate) use alloc::boxed::Box;
pub(crate) use alloc::string::String;
pub(crate) use alloc::vec::Vec;
Expand Down
2 changes: 1 addition & 1 deletion tests/bigint.rs
Expand Up @@ -187,7 +187,7 @@ fn test_signed_bytes_le_round_trip() {

#[test]
fn test_cmp() {
let vs: [&[u32]; 4] = [&[2 as u32], &[1, 1], &[2, 1], &[1, 1, 1]];
let vs: [&[u32]; 4] = [&[2_u32], &[1, 1], &[2, 1], &[1, 1, 1]];
let mut nums = Vec::new();
for s in vs.iter().rev() {
nums.push(BigInt::from_slice(Minus, *s));
Expand Down
2 changes: 1 addition & 1 deletion tests/modpow.rs
Expand Up @@ -120,7 +120,7 @@ mod bigint {
let even_m = m << 1u8;
let even_modpow = b.modpow(e, m);
assert!(even_modpow.abs() < even_m.abs());
assert_eq!(&even_modpow.mod_floor(&m), r);
assert_eq!(&even_modpow.mod_floor(m), r);

// the sign of the result follows the modulus like `mod_floor`, not `rem`
assert_eq!(b.modpow(&BigInt::one(), m), b.mod_floor(m));
Expand Down

0 comments on commit 2cea7f4

Please sign in to comment.