From dc9a828d78a7f0dc2ba83a31590893981962411c Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sat, 12 Aug 2023 16:18:56 +0700 Subject: [PATCH 1/5] clippy: Remove unnecessary casts. --- src/biguint/shift.rs | 4 ++-- tests/bigint.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/biguint/shift.rs b/src/biguint/shift.rs index 9fbeb02e..00326bb5 100644 --- a/src/biguint/shift.rs +++ b/src/biguint/shift.rs @@ -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; @@ -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; diff --git a/tests/bigint.rs b/tests/bigint.rs index 3144367f..75cf81ec 100644 --- a/tests/bigint.rs +++ b/tests/bigint.rs @@ -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)); From 544691f070df2da77a87aa41753932bd146a001e Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sat, 12 Aug 2023 16:37:16 +0700 Subject: [PATCH 2/5] clippy: Remove needless borrows. --- src/biguint/monty.rs | 4 ++-- src/biguint/power.rs | 10 +++++----- tests/modpow.rs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/biguint/monty.rs b/src/biguint/monty.rs index a5c79aa9..573f2dcc 100644 --- a/src/biguint/monty.rs +++ b/src/biguint/monty.rs @@ -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(); } diff --git a/src/biguint/power.rs b/src/biguint/power.rs index c2add8c4..621e1b15 100644 --- a/src/biguint/power.rs +++ b/src/biguint/power.rs @@ -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) ); } diff --git a/tests/modpow.rs b/tests/modpow.rs index 276f066e..d7a247b0 100644 --- a/tests/modpow.rs +++ b/tests/modpow.rs @@ -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)); From 61df9564c346657bd664e640add85d4f28eae791 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sat, 12 Aug 2023 16:39:45 +0700 Subject: [PATCH 3/5] clippy: Fix non-minimal-cfg --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c741f68f..fa83cf00 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; @@ -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; From cf5cc5bc46d73a37ef80a5bdca87906fd7f1b2fa Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sat, 12 Aug 2023 16:43:01 +0700 Subject: [PATCH 4/5] clippy: Suppress manual_range_contains. This requires Rust 1.35, higher than the current MSRV. --- src/biguint/convert.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/biguint/convert.rs b/src/biguint/convert.rs index e4f7f091..f19bc758 100644 --- a/src/biguint/convert.rs +++ b/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; From a87619daa467e2201c4380945671f45516e83bea Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sat, 12 Aug 2023 16:46:28 +0700 Subject: [PATCH 5/5] clippy: Fix auto deref warnings. --- src/bigint/convert.rs | 4 ++-- src/biguint.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bigint/convert.rs b/src/bigint/convert.rs index f3622035..774f20ba 100644 --- a/src/bigint/convert.rs +++ b/src/bigint/convert.rs @@ -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)) } @@ -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)) } diff --git a/src/biguint.rs b/src/biguint.rs index d1f60ce9..2ca6fc5a 100644 --- a/src/biguint.rs +++ b/src/biguint.rs @@ -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) } }