From 15a01a7e9ff3431dd7f0bf6da36c1a0a1fe8ce5a Mon Sep 17 00:00:00 2001 From: vil02 <65706193+vil02@users.noreply.github.com> Date: Thu, 27 Aug 2026 20:57:18 +0200 Subject: [PATCH] chore: resolve new clippy warnings --- src/bit_manipulation/binary_count_trailing_zeros.rs | 2 +- src/bit_manipulation/rightmost_set_bit.rs | 4 ++-- src/financial/exponential_moving_average.rs | 2 +- src/hashing/md5.rs | 2 +- src/hashing/sha2.rs | 8 ++++---- src/math/trapezoidal_integration.rs | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/bit_manipulation/binary_count_trailing_zeros.rs b/src/bit_manipulation/binary_count_trailing_zeros.rs index 5e6bd33ff3d..192706bac09 100644 --- a/src/bit_manipulation/binary_count_trailing_zeros.rs +++ b/src/bit_manipulation/binary_count_trailing_zeros.rs @@ -49,7 +49,7 @@ pub fn binary_count_trailing_zeros_bitwise(num: u64) -> u32 { return 0; } - let rightmost_set_bit = num & (num.wrapping_neg()); + let rightmost_set_bit = num.isolate_lowest_one(); rightmost_set_bit.ilog2() } diff --git a/src/bit_manipulation/rightmost_set_bit.rs b/src/bit_manipulation/rightmost_set_bit.rs index f35bdd998b3..0c8ad36b4ed 100644 --- a/src/bit_manipulation/rightmost_set_bit.rs +++ b/src/bit_manipulation/rightmost_set_bit.rs @@ -44,7 +44,7 @@ pub fn index_of_rightmost_set_bit(num: i32) -> Result { } // Isolate the rightmost set bit using n & -n - let rightmost_bit = num & -num; + let rightmost_bit = num.isolate_lowest_one(); // Calculate position: log2(rightmost_bit) + 1 // We use trailing_zeros which gives us the 0-based position @@ -72,7 +72,7 @@ pub fn index_of_rightmost_set_bit_log(num: i32) -> Result { } // Isolate the rightmost set bit - let rightmost_bit = num & -num; + let rightmost_bit = num.isolate_lowest_one(); // Use f64 log2 and convert to position let position = (rightmost_bit as f64).log2() as u32 + 1; diff --git a/src/financial/exponential_moving_average.rs b/src/financial/exponential_moving_average.rs index b1bcdd53006..cf627d827f0 100644 --- a/src/financial/exponential_moving_average.rs +++ b/src/financial/exponential_moving_average.rs @@ -50,7 +50,7 @@ pub fn exponential_moving_average( if i == 0 { stock_price } else { - (*moving_average + stock_price) * 0.5 + f64::midpoint(*moving_average, stock_price) } } else { // Apply exponential smoothing formula diff --git a/src/hashing/md5.rs b/src/hashing/md5.rs index 10fd2ababf9..b99794f500d 100644 --- a/src/hashing/md5.rs +++ b/src/hashing/md5.rs @@ -47,7 +47,7 @@ pub fn md5(input: &[u8]) -> [u8; 16] { msg.extend_from_slice(&bit_len.to_le_bytes()); // --- Processing: 512-bit (64-byte) chunks --- - for chunk in msg.chunks_exact(64) { + for chunk in msg.as_chunks::<64>().0 { // Break chunk into 16 little-endian 32-bit words let mut m = [0u32; 16]; for (i, word) in m.iter_mut().enumerate() { diff --git a/src/hashing/sha2.rs b/src/hashing/sha2.rs index d27e6d100c9..3ec70e27e7d 100644 --- a/src/hashing/sha2.rs +++ b/src/hashing/sha2.rs @@ -124,8 +124,8 @@ fn sha256_compress(state: &mut [u32; 8], block: &[u8; 64]) { fn sha256_hash(msg: &[u8], mut state: [u32; 8]) -> [u32; 8] { let padded = sha256_pad(msg); - for chunk in padded.chunks_exact(64) { - sha256_compress(&mut state, chunk.try_into().unwrap()); + for chunk in padded.as_chunks::<64>().0 { + sha256_compress(&mut state, chunk); } state } @@ -271,8 +271,8 @@ fn sha512_compress(state: &mut [u64; 8], block: &[u8; 128]) { fn sha512_hash(msg: &[u8], mut state: [u64; 8]) -> [u64; 8] { let padded = sha512_pad(msg); - for chunk in padded.chunks_exact(128) { - sha512_compress(&mut state, chunk.try_into().unwrap()); + for chunk in padded.as_chunks::<128>().0 { + sha512_compress(&mut state, chunk); } state } diff --git a/src/math/trapezoidal_integration.rs b/src/math/trapezoidal_integration.rs index f9cda7088c5..bde2e04fd5e 100644 --- a/src/math/trapezoidal_integration.rs +++ b/src/math/trapezoidal_integration.rs @@ -9,7 +9,7 @@ where let left_side = a + (delta * trapezoid as f64); let right_side = left_side + delta; - 0.5 * (f(left_side) + f(right_side)) * delta + f64::midpoint(f(left_side), f(right_side)) * delta }) .sum() }