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

Clippy fixes #278

Merged
merged 5 commits into from
Aug 22, 2023
Merged
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
4 changes: 2 additions & 2 deletions src/bigint/convert.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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