Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
result of applying `cargo clippy --fix` but excluding bits rearrangement
and temprorary allowing wrong_self_convention
  • Loading branch information
RCasatta committed Apr 21, 2023
1 parent 1575851 commit cf9c620
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ pub fn encode_auto(data: &[u8], ec_level: EcLevel) -> QrResult<Bits> {
let segments = Parser::new(data).collect::<Vec<Segment>>();
for version in &[Version::Normal(9), Version::Normal(26), Version::Normal(40)] {
let opt_segments = Optimizer::new(segments.iter().cloned(), *version).collect::<Vec<_>>();
let total_len = total_encoded_len(&*opt_segments, *version);
let total_len = total_encoded_len(&opt_segments, *version);
let data_capacity = version
.fetch(ec_level, &DATA_LENGTHS)
.expect("invalid DATA_LENGTHS");
Expand Down
4 changes: 2 additions & 2 deletions src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ pub fn is_functional(version: Version, width: i16, x: i16, y: i16) -> bool {
true
} else if a == 1 {
false
} else if 2 <= a && a <= 6 {
} else if (2..=6).contains(&a) {
(width - 7 - x).abs() <= 2 && (width - 7 - y).abs() <= 2
} else {
let positions = ALIGNMENT_PATTERN_POSITIONS[(a - 7).as_usize()];
Expand Down Expand Up @@ -1437,7 +1437,7 @@ impl Canvas {
} else {
Color::Dark
};
while let Some((x, y)) = coords.next() {
for (x, y) in coords.by_ref() {
let r = self.get_mut(x, y);
if *r == Module::Empty {
*r = Module::Unmasked(color);
Expand Down
2 changes: 1 addition & 1 deletion src/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub fn construct_codewords(
let ec_bytes = version.fetch(ec_level, &EC_BYTES_PER_BLOCK)?;
let ec_codes = blocks
.iter()
.map(|block| create_error_correction_code(*block, ec_bytes))
.map(|block| create_error_correction_code(block, ec_bytes))
.collect::<Vec<Vec<u8>>>();

let blocks_vec = interleave(&blocks);
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
clippy::must_use_candidate, // This is just annoying.
clippy::use_self, // Rust 1.33 doesn't support Self::EnumVariant, let's try again in 1.37.
clippy::match_like_matches_macro, // MSRV is lower than what's needed for matches!
clippy::wrong_self_convention, // TODO fix code and remove
)]
#![cfg_attr(feature = "bench", doc(include = "../README.md"))]
// ^ make sure we can test our README.md.
Expand Down Expand Up @@ -149,10 +150,10 @@ impl QrCode {
pub fn with_bits(bits: bits::Bits, ec_level: EcLevel) -> QrResult<Self> {
let version = bits.version();
let data = bits.into_bytes();
let (encoded_data, ec_data) = ec::construct_codewords(&*data, version, ec_level)?;
let (encoded_data, ec_data) = ec::construct_codewords(&data, version, ec_level)?;
let mut canvas = canvas::Canvas::new(version, ec_level);
canvas.draw_all_functional_patterns();
canvas.draw_data(&*encoded_data, &*ec_data);
canvas.draw_data(&encoded_data, &ec_data);
let canvas = canvas.apply_best_mask();
Ok(Self {
content: canvas.into_colors(),
Expand Down Expand Up @@ -202,7 +203,7 @@ impl QrCode {

/// Returns an iterator over QR code vector of colors.
pub fn iter(&self) -> QrCodeIterator {
QrCodeIterator::new(&self)
QrCodeIterator::new(self)
}

/// Converts the QR code to a vector of colors.
Expand Down
8 changes: 4 additions & 4 deletions src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,17 @@ mod optimize_tests {
use crate::types::{Mode, Version};

fn test_optimization_result(given: Vec<Segment>, expected: Vec<Segment>, version: Version) {
let prev_len = total_encoded_len(&*given, version);
let opt_segs = Optimizer::new(given.iter().map(|seg| *seg), version).collect::<Vec<_>>();
let new_len = total_encoded_len(&*opt_segs, version);
let prev_len = total_encoded_len(&given, version);
let opt_segs = Optimizer::new(given.iter().copied(), version).collect::<Vec<_>>();
let new_len = total_encoded_len(&opt_segs, version);
if given != opt_segs {
assert!(prev_len > new_len, "{} > {}", prev_len, new_len);
}
assert!(
opt_segs == expected,
"Optimization gave something better: {} < {} ({:?})",
new_len,
total_encoded_len(&*expected, version),
total_encoded_len(&expected, version),
opt_segs
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl QrCode {
(Color::Dark, Color::Light) => 2,
(Color::Dark, Color::Dark) => 3,
};
result.push_str(&blocks[val + inverted].to_string());
result.push_str(blocks[val + inverted]);
}
result.push_str(&border_blocks);
result.push('\n');
Expand Down
13 changes: 6 additions & 7 deletions src/structured.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ pub fn merge_qrs(mut bytes: Vec<Vec<u8>>) -> QrResult<Vec<u8>> {
vec_structured.sort_by(|a, b| a.seq.cmp(&b.seq)); // allows to merge out of order by reordering here
let result: Vec<u8> = vec_structured
.iter()
.map(|q| q.content.clone())
.flatten()
.flat_map(|q| q.content.clone())
.collect();

let final_parity = result.iter().fold(0u8, |acc, &x| acc ^ x);
Expand Down Expand Up @@ -141,7 +140,7 @@ impl TryFrom<Vec<u8>> for StructuredQr {
if value.len() < end {
return Err(Structured(LengthMismatch(end, value.len())));
}
let content = (&value[from..end]).to_vec();
let content = value[from..end].to_vec();
//TODO check padding

Ok(StructuredQr {
Expand Down Expand Up @@ -208,7 +207,7 @@ impl SplittedQr {
pub fn split(&self) -> QrResult<Vec<QrCode>> {
self.split_to_bits()?
.into_iter()
.map(|bits| Ok(QrCode::with_bits(bits, LEVEL)?))
.map(|bits| QrCode::with_bits(bits, LEVEL))
.collect()
}

Expand Down Expand Up @@ -307,7 +306,7 @@ mod tests {
let result = merge_qrs(vec);
assert_eq!(result.unwrap_err().to_string(), AtLeast2Pieces.to_string());

let vec = vec![first.clone(), full_content.clone()];
let vec = vec![first.clone(), full_content];
let result = merge_qrs(vec);
assert_eq!(
result.unwrap_err().to_string(),
Expand All @@ -320,7 +319,7 @@ mod tests {
let result = merge_qrs(vec);
assert_eq!(result.unwrap_err().to_string(), MissingParts.to_string());

let vec = vec![first.clone(), first_mut.clone(), second.clone()];
let vec = vec![first, first_mut.clone(), second];
let result = merge_qrs(vec);
assert_eq!(
result.unwrap_err().to_string(),
Expand Down Expand Up @@ -355,7 +354,7 @@ mod tests {
for _ in 0..1_000 {
let len = rng.gen_range(100, 4000);
let ver = rng.gen_range(10, 20);
let data = (&random_bytes[0..len]).to_vec();
let data = random_bytes[0..len].to_vec();
let split_qr = SplittedQr::new(data.clone(), ver).unwrap();
let bits = split_qr.split_to_bits().unwrap();
if bits.len() > 1 {
Expand Down

0 comments on commit cf9c620

Please sign in to comment.