From a75279df1f5417b07a5803b617b063f6b30f963d Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 10 Aug 2022 21:47:33 +0200 Subject: [PATCH] OOOO MIGHTY CLIPPY, WE SUMMON YOU!!! --- ext2-rs/src/fs/sync.rs | 18 +++++------ ext2-rs/src/sector.rs | 4 +-- ext2-rs/src/volume/mod.rs | 2 +- qrcode-rust/src/bits.rs | 54 +++++++++++++++---------------- qrcode-rust/src/canvas.rs | 6 ++-- qrcode-rust/src/ec.rs | 2 +- qrcode-rust/src/lib.rs | 4 +-- qrcode-rust/src/optimize.rs | 13 ++++---- qrcode-rust/src/render/unicode.rs | 2 +- x86_ata/src/lib.rs | 10 +++--- 10 files changed, 57 insertions(+), 58 deletions(-) diff --git a/ext2-rs/src/fs/sync.rs b/ext2-rs/src/fs/sync.rs index 25e01e15..bda8360d 100644 --- a/ext2-rs/src/fs/sync.rs +++ b/ext2-rs/src/fs/sync.rs @@ -50,7 +50,7 @@ impl Clone for Synced { impl> Synced> { /// DOCME: what is this? pub fn new(volume: V) -> Result>, Error> { - Ext2::new(volume).map(|inner| Synced::with_inner(inner)) + Ext2::new(volume).map(Synced::with_inner) } /// Get the root inode. pub fn root_inode(&self) -> Inode { @@ -139,7 +139,7 @@ impl> Fs for Synced> { inner(fs, inode, path, abs_path) } - if abs_path.len() == 0 || abs_path[0] != b'/' { + if abs_path.is_empty() || abs_path[0] != b'/' { return Err(Error::NotAbsolute { name: String::from_utf8_lossy(abs_path).into_owned(), }); @@ -355,17 +355,17 @@ impl> Inode { buf.set_len(total_size); } let size = self.read(&mut buf[..]); - size.and_then(|size| { + size.map(|size| { unsafe { buf.set_len(size); } - Ok(size) + size }) - .or_else(|err| { + .map_err(|err| { unsafe { buf.set_len(0); } - Err(err) + err }) } /// Return blocks on a sector @@ -571,7 +571,7 @@ impl> File for Inode { buf[offset..end].copy_from_slice(&data[..data_size]); offset += data_size; } - Err(err) => return Err(err.into()), + Err(err) => return Err(err), } } @@ -673,9 +673,9 @@ impl> Iterator for Directory { self.offset += size as usize; Some(Ok(DirectoryEntry { - name: name, + name, inode: inode as usize, - ty: ty, + ty, })) } } diff --git a/ext2-rs/src/sector.rs b/ext2-rs/src/sector.rs index eb4a392a..f657e3a3 100644 --- a/ext2-rs/src/sector.rs +++ b/ext2-rs/src/sector.rs @@ -65,7 +65,7 @@ impl Address { /// pub fn new(sector: u32, offset: i32) -> Address { let sector = (sector as i32 + (offset >> S::LOG_SIZE)) as u32; - let offset = offset.abs() as u32 & S::OFFSET_MASK; + let offset = offset.unsigned_abs() & S::OFFSET_MASK; unsafe { Address::new_unchecked(sector, offset) } } /// @@ -75,7 +75,7 @@ impl Address { log_block_size: u32, ) -> Address { let block = (block as i32 + (offset >> log_block_size)) as u32; - let offset = offset.abs() as u32 & ((1 << log_block_size) - 1); + let offset = offset.unsigned_abs() & ((1 << log_block_size) - 1); let log_diff = log_block_size as i32 - S::LOG_SIZE as i32; let top_offset = offset >> S::LOG_SIZE; diff --git a/ext2-rs/src/volume/mod.rs b/ext2-rs/src/volume/mod.rs index 386fdda9..d3d23b61 100644 --- a/ext2-rs/src/volume/mod.rs +++ b/ext2-rs/src/volume/mod.rs @@ -36,7 +36,7 @@ pub trait Volume { ) -> Result, Self::Error>; } -#[derive(Debug, Clone, PartialEq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct VolumeSlice<'a, T: 'a + Clone, S: SectorSize> { inner: Cow<'a, [T]>, index: Address, diff --git a/qrcode-rust/src/bits.rs b/qrcode-rust/src/bits.rs index 22471f34..1273626f 100644 --- a/qrcode-rust/src/bits.rs +++ b/qrcode-rust/src/bits.rs @@ -135,14 +135,14 @@ fn test_push_number() { assert_eq!( bytes, vec![ - 0b010__110__10, // 90 - 0b1__001_1010, // 154 - 0b1100__1011, // 203 + 0b0101_1010, // 90 + 0b1001_1010, // 154 + 0b1100_1011, // 203 0b0110_1101, // 109 0b01_1001_00, // 100 - 0b01__111_001, // 121 - 0b0_1110_001, // 113 - 0b1__0000000, // 128 + 0b0111_1001, // 121 + 0b0111_0001, // 113 + 0b1000_0000, // 128 ] ); } @@ -287,21 +287,21 @@ mod eci_tests { fn test_9() { let mut bits = Bits::new(Version::Normal(1)); assert_eq!(bits.push_eci_designator(9), Ok(())); - assert_eq!(bits.into_bytes(), vec![0b0111__0000, 0b1001__0000]); + assert_eq!(bits.into_bytes(), vec![0b0111_0000, 0b1001_0000]); } #[test] fn test_899() { let mut bits = Bits::new(Version::Normal(1)); assert_eq!(bits.push_eci_designator(899), Ok(())); - assert_eq!(bits.into_bytes(), vec![0b0111__10_00, 0b00111000, 0b0011__0000]); + assert_eq!(bits.into_bytes(), vec![0b0111_1000, 0b00111000, 0b0011_0000]); } #[test] fn test_999999() { let mut bits = Bits::new(Version::Normal(1)); assert_eq!(bits.push_eci_designator(999999), Ok(())); - assert_eq!(bits.into_bytes(), vec![0b0111__110_0, 0b11110100, 0b00100011, 0b1111__0000]); + assert_eq!(bits.into_bytes(), vec![0b0111_1100, 0b11110100, 0b00100011, 0b1111_0000]); } #[test] @@ -359,7 +359,7 @@ mod numeric_tests { assert_eq!(bits.push_numeric_data(b"01234567"), Ok(())); assert_eq!( bits.into_bytes(), - vec![0b0001_0000, 0b001000_00, 0b00001100, 0b01010110, 0b01_100001, 0b1__0000000] + vec![0b0001_0000, 0b001000_00, 0b00001100, 0b01010110, 0b0110_0001, 0b1000_0000] ); } @@ -374,11 +374,11 @@ mod numeric_tests { 0b010000_00, 0b00001100, 0b01010110, - 0b01_101010, + 0b0110_1010, 0b0110_1110, 0b000101_00, 0b11101010, - 0b0101__0000, + 0b0101_0000, ] ); } @@ -390,14 +390,14 @@ mod numeric_tests { assert_eq!( bits.into_bytes(), vec![ - 0b00_10000_0, + 0b0010_0000, 0b00000110, - 0b0_0101011, - 0b001_10101, - 0b00110_111, - 0b0000101_0, + 0b0010_1011, + 0b0011_0101, + 0b0011_0111, + 0b0000_1010, 0b01110101, - 0b00101__000, + 0b0010_1000, ] ); } @@ -467,7 +467,7 @@ mod alphanumeric_tests { assert_eq!(bits.push_alphanumeric_data(b"AC-42"), Ok(())); assert_eq!( bits.into_bytes(), - vec![0b0010_0000, 0b00101_001, 0b11001110, 0b11100111, 0b001_00001, 0b0__0000000] + vec![0b0010_0000, 0b0010_1001, 0b11001110, 0b11100111, 0b0010_0001, 0b0000_0000] ); } @@ -524,7 +524,7 @@ mod byte_tests { 0b1010_1011, 0b1100_1101, 0b1110_1111, - 0b0000__0000, + 0b0000_0000, ] ); } @@ -579,7 +579,7 @@ mod kanji_tests { fn test_iso_18004_example() { let mut bits = Bits::new(Version::Normal(1)); assert_eq!(bits.push_kanji_data(b"\x93\x5f\xe4\xaa"), Ok(())); - assert_eq!(bits.into_bytes(), vec![0b1000_0000, 0b0010_0110, 0b11001111, 0b1_1101010, 0b101010__00]); + assert_eq!(bits.into_bytes(), vec![0b1000_0000, 0b0010_0110, 0b11001111, 0b1110_1010, 0b1010_1000]); } #[test] @@ -785,7 +785,7 @@ mod finish_tests { let mut bits = Bits::new(Version::Micro(1)); assert_eq!(bits.push_numeric_data(b"99999"), Ok(())); assert_eq!(bits.push_terminator(EcLevel::L), Ok(())); - assert_eq!(bits.into_bytes(), vec![0b101_11111, 0b00111_110, 0b0011__0000]); + assert_eq!(bits.into_bytes(), vec![0b1011_1111, 0b0011_1110, 0b0011_0000]); } #[test] @@ -793,7 +793,7 @@ mod finish_tests { let mut bits = Bits::new(Version::Micro(1)); assert_eq!(bits.push_numeric_data(b"9999"), Ok(())); assert_eq!(bits.push_terminator(EcLevel::L), Ok(())); - assert_eq!(bits.into_bytes(), vec![0b100_11111, 0b00111_100, 0b1_000__0000]); + assert_eq!(bits.into_bytes(), vec![0b1001_1111, 0b0011_1100, 0b1000_0000]); } #[test] @@ -801,7 +801,7 @@ mod finish_tests { let mut bits = Bits::new(Version::Micro(1)); assert_eq!(bits.push_numeric_data(b"999"), Ok(())); assert_eq!(bits.push_terminator(EcLevel::L), Ok(())); - assert_eq!(bits.into_bytes(), vec![0b011_11111, 0b00111_000, 0b0000__0000]); + assert_eq!(bits.into_bytes(), vec![0b0111_1111, 0b0011_1000, 0b0000_0000]); } #[test] @@ -809,7 +809,7 @@ mod finish_tests { let mut bits = Bits::new(Version::Micro(1)); assert_eq!(bits.push_numeric_data(b""), Ok(())); assert_eq!(bits.push_terminator(EcLevel::L), Ok(())); - assert_eq!(bits.into_bytes(), vec![0b000_000_00, 0b11101100, 0]); + assert_eq!(bits.into_bytes(), vec![0b0000_0000, 0b11101100, 0]); } } @@ -882,7 +882,7 @@ mod encode_tests { #[test] fn test_auto_mode_switch() { let res = encode(b"123A", Version::Micro(2), EcLevel::L); - assert_eq!(res, Ok(vec![0b0_0011_000, 0b1111011_1, 0b001_00101, 0b0_00000__00, 0b11101100])); + assert_eq!(res, Ok(vec![0b0001_1000, 0b1111_0111, 0b0010_0101, 0b0000_0000, 0b11101100])); } #[test] @@ -909,7 +909,7 @@ pub fn encode_auto(data: &[u8], ec_level: EcLevel) -> QrResult { let segments = Parser::new(data).collect::>(); for version in &[Version::Normal(9), Version::Normal(26), Version::Normal(40)] { let opt_segments = Optimizer::new(segments.iter().cloned(), *version).collect::>(); - 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"); if total_len <= data_capacity { let min_version = find_min_version(total_len, ec_level); diff --git a/qrcode-rust/src/canvas.rs b/qrcode-rust/src/canvas.rs index f30d75a8..0e974cec 100644 --- a/qrcode-rust/src/canvas.rs +++ b/qrcode-rust/src/canvas.rs @@ -999,7 +999,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()]; @@ -1193,7 +1193,7 @@ impl Iterator for DataModuleIter { #[cfg(test)] #[rustfmt::skip] // skip to prevent file becoming too long. mod data_iter_tests { - use alloc::vec::{*,Vec}; + use alloc::vec::{Vec}; use crate::canvas::DataModuleIter; use crate::types::Version; @@ -1373,7 +1373,7 @@ impl Canvas { let bits_end = if i == last_word { 4 } else { 0 }; 'outside: for j in (bits_end..=7).rev() { let color = if (*b & (1 << j)) == 0 { Color::Light } 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); diff --git a/qrcode-rust/src/ec.rs b/qrcode-rust/src/ec.rs index b37b6f11..7903abbe 100644 --- a/qrcode-rust/src/ec.rs +++ b/qrcode-rust/src/ec.rs @@ -124,7 +124,7 @@ pub fn construct_codewords(rawbits: &[u8], version: Version, ec_level: EcLevel) // Generate EC codes. 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)).collect::>>(); + let ec_codes = blocks.iter().map(|block| create_error_correction_code(block, ec_bytes)).collect::>>(); let blocks_vec = interleave(&blocks); let ec_vec = interleave(&ec_codes); diff --git a/qrcode-rust/src/lib.rs b/qrcode-rust/src/lib.rs index e188d704..f7346d94 100644 --- a/qrcode-rust/src/lib.rs +++ b/qrcode-rust/src/lib.rs @@ -160,10 +160,10 @@ impl QrCode { pub fn with_bits(bits: bits::Bits, ec_level: EcLevel) -> QrResult { 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(), version, ec_level, width: version.width().as_usize() }) } diff --git a/qrcode-rust/src/optimize.rs b/qrcode-rust/src/optimize.rs index 2ba8cd61..7a59c11e 100644 --- a/qrcode-rust/src/optimize.rs +++ b/qrcode-rust/src/optimize.rs @@ -1,7 +1,6 @@ //! Find the optimal data mode sequence to encode a piece of data. use crate::types::{Mode, Version}; -#[cfg(test)] -use alloc::vec::{self, Vec, *}; + use core::slice::Iter; @@ -156,7 +155,7 @@ impl<'a> Iterator for Parser<'a> { #[cfg(test)] mod parse_tests { - use alloc::vec::{self, Vec}; + use alloc::vec::{Vec}; use crate::optimize::{Parser, Segment}; use crate::types::Mode; @@ -347,9 +346,9 @@ mod optimize_tests { use crate::types::{Mode, Version}; fn test_optimization_result(given: Vec, expected: Vec, version: Version) { - let prev_len = total_encoded_len(&*given, version); - let opt_segs = Optimizer::new(given.iter().map(|seg| *seg), version).collect::>(); - 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::>(); + let new_len = total_encoded_len(&opt_segs, version); if given != opt_segs { assert!(prev_len > new_len, "{} > {}", prev_len, new_len); } @@ -357,7 +356,7 @@ mod optimize_tests { opt_segs == expected, "Optimization gave something better: {} < {} ({:?})", new_len, - total_encoded_len(&*expected, version), + total_encoded_len(&expected, version), opt_segs ); } diff --git a/qrcode-rust/src/render/unicode.rs b/qrcode-rust/src/render/unicode.rs index 10d80e3e..11e7a2c0 100644 --- a/qrcode-rust/src/render/unicode.rs +++ b/qrcode-rust/src/render/unicode.rs @@ -5,7 +5,7 @@ use alloc::{string::String, vec::Vec}; const CODEPAGE: [&str; 4] = [" ", "\u{2584}", "\u{2580}", "\u{2588}"]; -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq, Eq)] pub enum Dense1x2 { Dark, Light, diff --git a/x86_ata/src/lib.rs b/x86_ata/src/lib.rs index 15a9fcc8..b2e760f4 100644 --- a/x86_ata/src/lib.rs +++ b/x86_ata/src/lib.rs @@ -71,7 +71,7 @@ impl Bus { id, irq, - data_register: Port::new(io_base + 0), + data_register: Port::new(io_base), error_register: PortReadOnly::new(io_base + 1), features_register: PortWriteOnly::new(io_base + 1), sector_count_register: Port::new(io_base + 2), @@ -82,8 +82,8 @@ impl Bus { status_register: PortReadOnly::new(io_base + 7), command_register: PortWriteOnly::new(io_base + 7), - alternate_status_register: PortReadOnly::new(ctrl_base + 0), - control_register: PortWriteOnly::new(ctrl_base + 0), + alternate_status_register: PortReadOnly::new(ctrl_base), + control_register: PortWriteOnly::new(ctrl_base), drive_blockess_register: PortReadOnly::new(ctrl_base + 1), } } @@ -248,7 +248,7 @@ impl Bus { let data = self.read_data(); //log!("Read[{:08X}][{:02X}]: 0x{:04X}\n", block, i, data); - buf[i + 0] = data.get_bits(0..8) as u8; + buf[i] = data.get_bits(0..8) as u8; buf[i + 1] = data.get_bits(8..16) as u8; } } @@ -274,7 +274,7 @@ impl Bus { self.write_command(Command::Write); self.busy_loop(); for i in 0..256 { - let mut data = 0 as u16; + let mut data = 0_u16; data.set_bits(0..8, buf[i * 2] as u16); data.set_bits(8..16, buf[i * 2 + 1] as u16);