From 634722a8066001085d0a169f377f3761a72b2e56 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Thu, 4 May 2023 13:45:57 -0500 Subject: [PATCH] cargo clippy --fix --- .../result/AddressBookParsedResultTestCase.rs | 1 + .../result/CalendarParsedResultTestCase.rs | 1 + src/client/result/VINParsedResultTestCase.rs | 1 + src/common/bit_array.rs | 4 ++-- src/common/bit_source.rs | 2 +- .../base_extentions/qr_formatinformation.rs | 4 ++-- .../base_extentions/qrcode_version.rs | 8 +++----- src/common/cpp_essentials/decoder_result.rs | 8 ++++---- src/common/cpp_essentials/pattern.rs | 10 +++++----- src/common/default_grid_sampler.rs | 2 +- src/common/reedsolomon/ReedSolomonTestCase.rs | 5 +++-- src/oned/rss/expanded/bit_array_builder.rs | 4 ++-- src/qrcode/cpp_port/decoder.rs | 15 +++++++-------- src/qrcode/cpp_port/detector.rs | 14 +++++++------- src/qrcode/encoder/MaskUtilTestCase.rs | 2 +- src/rxing_result_point.rs | 19 +++++++++---------- 16 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/client/result/AddressBookParsedResultTestCase.rs b/src/client/result/AddressBookParsedResultTestCase.rs index 6a77d77..d5a58c8 100644 --- a/src/client/result/AddressBookParsedResultTestCase.rs +++ b/src/client/result/AddressBookParsedResultTestCase.rs @@ -334,6 +334,7 @@ fn testVCardTypes() { ); } +#[allow(clippy::too_many_arguments)] fn doTest( contents: &str, title: &str, diff --git a/src/client/result/CalendarParsedResultTestCase.rs b/src/client/result/CalendarParsedResultTestCase.rs index 45a2abd..ad63560 100644 --- a/src/client/result/CalendarParsedResultTestCase.rs +++ b/src/client/result/CalendarParsedResultTestCase.rs @@ -197,6 +197,7 @@ fn doTestShort( ); } +#[allow(clippy::too_many_arguments)] fn doTest( contents: &str, description: &str, diff --git a/src/client/result/VINParsedResultTestCase.rs b/src/client/result/VINParsedResultTestCase.rs index da6c1eb..4e3ef4f 100644 --- a/src/client/result/VINParsedResultTestCase.rs +++ b/src/client/result/VINParsedResultTestCase.rs @@ -82,6 +82,7 @@ fn test_vin() { ); } +#[allow(clippy::too_many_arguments)] fn do_test( contents: &str, wmi: &str, diff --git a/src/common/bit_array.rs b/src/common/bit_array.rs index 402c012..058b9e2 100644 --- a/src/common/bit_array.rs +++ b/src/common/bit_array.rs @@ -429,8 +429,8 @@ impl Into> for BitArray { fn into(self) -> Vec { let mut array = vec![false; self.size]; - for pixel in 0..self.size { - array[pixel] = self.get(pixel); + for (pixel, element) in array.iter_mut().enumerate().take(self.size) { + *element = self.get(pixel); } array diff --git a/src/common/bit_source.rs b/src/common/bit_source.rs index 2d9bae2..795209d 100644 --- a/src/common/bit_source.rs +++ b/src/common/bit_source.rs @@ -139,7 +139,7 @@ impl BitSource { num_bits -= toRead; bit_offset += toRead; if bit_offset == 8 { - bit_offset = 0; + //bit_offset = 0; byte_offset += 1; } } diff --git a/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs b/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs index 5e785b3..398a54b 100644 --- a/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs +++ b/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs @@ -100,12 +100,12 @@ impl FormatInformation { // Some QR codes apparently do not apply the XOR mask. Try without and with additional masking. for mask in [0, mask] { // for (auto mask : {0, mask}) - for bitsIndex in 0..bits.len() { + for (bitsIndex, bit_set) in bits.iter().enumerate() { // for (int bitsIndex = 0; bitsIndex < Size(bits); ++bitsIndex) for [pattern, index] in lookup { // for (const auto& [pattern, index] : lookup) { // Find the int in lookup with fewest bits differing - let hammingDist = ((bits[bitsIndex] ^ mask) ^ pattern).count_ones(); + let hammingDist = ((bit_set ^ mask) ^ pattern).count_ones(); if hammingDist < fi.hammingDistance { // if (int hammingDist = BitHacks::CountBitsSet((bits[bitsIndex] ^ mask) ^ pattern); hammingDist < fi.hammingDistance) { fi.index = index as u8; diff --git a/src/common/cpp_essentials/base_extentions/qrcode_version.rs b/src/common/cpp_essentials/base_extentions/qrcode_version.rs index b471e35..e33f9a2 100644 --- a/src/common/cpp_essentials/base_extentions/qrcode_version.rs +++ b/src/common/cpp_essentials/base_extentions/qrcode_version.rs @@ -63,12 +63,11 @@ impl Version { pub fn DecodeVersionInformation(versionBitsA: i32, versionBitsB: i32) -> Result { let mut bestDifference = u32::MAX; let mut bestVersion = 0; - let mut i = 0; - for targetVersion in VERSION_DECODE_INFO { + for (i, targetVersion) in VERSION_DECODE_INFO.into_iter().enumerate() { // for (int targetVersion : VERSION_DECODE_INFO) { // Do the version info bits match exactly? done. if targetVersion == versionBitsA as u32 || targetVersion == versionBitsB as u32 { - return Self::getVersionForNumber(i + 7); + return Self::getVersionForNumber(i as u32 + 7); } // Otherwise see if this is the closest to a real version info bit string // we have seen so far @@ -80,12 +79,11 @@ impl Version { bestDifference = bitsDifference; } } - i += 1; } // We can tolerate up to 3 bits of error since no two version info codewords will // differ in less than 8 bits. if bestDifference <= 3 { - return Self::getVersionForNumber(bestVersion); + return Self::getVersionForNumber(bestVersion as u32); } // If we didn't find a close enough match, fail Err(Exceptions::ILLEGAL_STATE) diff --git a/src/common/cpp_essentials/decoder_result.rs b/src/common/cpp_essentials/decoder_result.rs index feac994..bd0967c 100644 --- a/src/common/cpp_essentials/decoder_result.rs +++ b/src/common/cpp_essentials/decoder_result.rs @@ -49,10 +49,10 @@ where Self::default() } pub fn with_eci_string_builder(src: ECIStringBuilder) -> Self { - let mut new_self = Self::default(); - new_self.content = src; - - new_self + DecoderResult:: { + content: src, + ..Default::default() + } } pub fn isValid(&self) -> bool { diff --git a/src/common/cpp_essentials/pattern.rs b/src/common/cpp_essentials/pattern.rs index db16934..d299275 100644 --- a/src/common/cpp_essentials/pattern.rs +++ b/src/common/cpp_essentials/pattern.rs @@ -80,7 +80,7 @@ pub struct PatternViewIterator<'a> { current_position: usize, } -impl<'a> Iterator for PatternViewIterator<'_> { +impl Iterator for PatternViewIterator<'_> { type Item = PatternType; fn next(&mut self) -> Option { @@ -243,7 +243,7 @@ impl<'a> PatternView<'a> { pub fn shift(&mut self, n: usize) -> bool { self.current += n; - !self.data.0.is_empty() && self.start + self.count <= (self.start + self.count) + !self.data.0.is_empty() //&& self.start + self.count <= (self.start + self.count) } pub fn skipPair(&mut self) -> bool { @@ -278,7 +278,7 @@ impl<'a> PatternView<'a> { } } -impl<'a> std::ops::Index for PatternView<'_> { +impl std::ops::Index for PatternView<'_> { type Output = PatternType; fn index(&self, index: isize) -> &Self::Output { @@ -301,7 +301,7 @@ impl<'a> std::ops::Index for PatternView<'_> { } } -impl<'a> std::ops::Index for PatternView<'_> { +impl std::ops::Index for PatternView<'_> { type Output = PatternType; fn index(&self, index: usize) -> &Self::Output { @@ -316,7 +316,7 @@ impl<'a> std::ops::Index for PatternView<'_> { } } -impl<'a> std::ops::Index for PatternView<'_> { +impl std::ops::Index for PatternView<'_> { type Output = PatternType; fn index(&self, index: i32) -> &Self::Output { diff --git a/src/common/default_grid_sampler.rs b/src/common/default_grid_sampler.rs index 8e80e2f..54bef50 100644 --- a/src/common/default_grid_sampler.rs +++ b/src/common/default_grid_sampler.rs @@ -37,7 +37,7 @@ impl GridSampler for DefaultGridSampler { dimensionY: u32, controls: &[SamplerControl], ) -> Result<(BitMatrix, [Point; 4])> { - if dimensionX <= 0 || dimensionY <= 0 { + if dimensionX == 0 || dimensionY == 0 { return Err(Exceptions::NOT_FOUND); } diff --git a/src/common/reedsolomon/ReedSolomonTestCase.rs b/src/common/reedsolomon/ReedSolomonTestCase.rs index efc9250..6587b20 100644 --- a/src/common/reedsolomon/ReedSolomonTestCase.rs +++ b/src/common/reedsolomon/ReedSolomonTestCase.rs @@ -417,9 +417,10 @@ fn test_encode_decode_random(field: GenericGFRef, dataSize: usize, ecSize: usize for _i in 0..iterations { //for (int i = 0; i < iterations; i++) { // generate random data - for k in 0..dataSize { + for data in dataWords.iter_mut().take(dataSize) { + // for k in 0..dataSize { //for (int k = 0; k < dataSize; k++) { - dataWords[k] = random.gen_range(0..field.getSize().try_into().unwrap()); + *data = random.gen_range(0..field.getSize().try_into().unwrap()); } // generate ECC words message[0..dataWords.len()].clone_from_slice(&dataWords[..]); diff --git a/src/oned/rss/expanded/bit_array_builder.rs b/src/oned/rss/expanded/bit_array_builder.rs index 10abb84..8c96474 100644 --- a/src/oned/rss/expanded/bit_array_builder.rs +++ b/src/oned/rss/expanded/bit_array_builder.rs @@ -116,12 +116,12 @@ mod BitArrayBuilderTest { checkBinary(&pairValues, expected); } - fn checkBinary(pairValues: &Vec>, expected: &str) { + fn checkBinary(pairValues: &[Vec], expected: &str) { let binary = buildBitArray(pairValues); assert_eq!(expected, binary.to_string()); } - fn buildBitArray(pairValues: &Vec>) -> BitArray { + fn buildBitArray(pairValues: &[Vec]) -> BitArray { let mut pairs = Vec::new(); //new ArrayList<>(); for (i, pair) in pairValues.iter().enumerate() { // for (int i = 0; i < pairValues.length; ++i) { diff --git a/src/qrcode/cpp_port/decoder.rs b/src/qrcode/cpp_port/decoder.rs index 491b639..eb558f7 100644 --- a/src/qrcode/cpp_port/decoder.rs +++ b/src/qrcode/cpp_port/decoder.rs @@ -137,8 +137,8 @@ pub fn DecodeByteSegment( pub fn ToAlphaNumericChar(value: u32) -> Result { let value = value as usize; /** - * See ISO 18004:2006, 6.4.4 Table 5 - */ + * See ISO 18004:2006, 6.4.4 Table 5 + */ const ALPHANUMERIC_CHARS: [char; 45] = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', @@ -301,15 +301,14 @@ pub fn DecodeBitStream( let res = (|| { while !IsEndOfStream(&mut bits, version)? { - let mode: Mode; - if modeBitLength == 0 { - mode = Mode::NUMERIC; // MicroQRCode version 1 is always NUMERIC and modeBitLength is 0 + let mode: Mode = if modeBitLength == 0 { + Mode::NUMERIC // MicroQRCode version 1 is always NUMERIC and modeBitLength is 0 } else { - mode = Mode::CodecModeForBits( + Mode::CodecModeForBits( bits.readBits(modeBitLength as usize)?, Some(version.isMicroQRCode()), - )?; - } + )? + }; match mode { Mode::FNC1_FIRST_POSITION => { diff --git a/src/qrcode/cpp_port/detector.rs b/src/qrcode/cpp_port/detector.rs index c091895..2b664ef 100644 --- a/src/qrcode/cpp_port/detector.rs +++ b/src/qrcode/cpp_port/detector.rs @@ -99,10 +99,9 @@ pub fn FindFinderPatterns(image: &BitMatrix, tryHarder: bool) -> FinderPatterns ); // make sure p is not 'inside' an already found pattern area - if res + if !res .iter() - .find(|old| Point::distance(p, old.p) < (old.size as f32) / 2.0) - .is_none() + .any(|old| Point::distance(p, old.p) < (old.size as f32) / 2.0) { // if (FindIf(res, [p](const auto& old) { return distance(p, old) < old.size / 2; }) == res.end()) { let pattern = LocateConcentricPattern::( @@ -149,8 +148,8 @@ pub fn GenerateFinderPatternSets(patterns: &mut FinderPatterns) -> FinderPattern * (((b).size as f64) / ((a).size as f64)).powi(2) //std::pow(double(b.size) / a.size, 2) }; - let cosUpper: f64 = (45.0_f64 / 180.0 * 3.1415).cos(); // TODO: use c++20 std::numbers::pi_v - let cosLower: f64 = (135.0_f64 / 180.0 * 3.1415).cos(); + let cosUpper: f64 = (45.0_f64 / 180.0 * std::f64::consts::PI).cos(); // TODO: use c++20 std::numbers::pi_v + let cosLower: f64 = (135.0_f64 / 180.0 * std::f64::consts::PI).cos(); let nbPatterns = (patterns).len(); @@ -1014,12 +1013,13 @@ pub fn SampleMQR(image: &BitMatrix, fp: ConcentricPattern) -> Result>) -> bool { +fn testGetDataMaskBitInternal(maskPattern: u32, expected: &[Vec]) -> bool { for x in 0..6 { // for (int x = 0; x < 6; ++x) { for y in 0..6 { diff --git a/src/rxing_result_point.rs b/src/rxing_result_point.rs index 979af5f..d0f14a7 100644 --- a/src/rxing_result_point.rs +++ b/src/rxing_result_point.rs @@ -1,4 +1,3 @@ - use std::{fmt, iter::Sum}; use std::hash::Hash; @@ -31,20 +30,20 @@ pub type PointF = PointT; pub type PointI = PointT; pub type Point = PointF; -impl Into for Point { - fn into(self) -> PointI { +impl From for PointI { + fn from(val: Point) -> Self { PointI { - x: self.x.floor() as u32, - y: self.y.floor() as u32, + x: val.x.floor() as u32, + y: val.y.floor() as u32, } } } -impl Into for PointI { - fn into(self) -> Point { +impl From for Point { + fn from(val: PointI) -> Self { Point { - x: self.x as f32, - y: self.y as f32, + x: val.x as f32, + y: val.y as f32, } } } @@ -81,7 +80,7 @@ where T: Copy, { pub const fn new(x: T, y: T) -> PointT { - PointT { x: x, y: y } + PointT { x, y } } pub const fn with_single(x: T) -> Self { Self { x, y: x }