From 945dcbae1d44afee5783260d64ebbb242f047881 Mon Sep 17 00:00:00 2001 From: theironchef <6278036+theironchef@users.noreply.github.com> Date: Mon, 5 Oct 2026 07:40:20 -0700 Subject: [PATCH] Lint: as_chunks for constant chunk sizes, as clippy 1.99 asks Rust 1.99's clippy adds chunks_exact_to_as_chunks, and cargo clippy --workspace --all-targets -D warnings (cargo xtask ci) failed on its eight hits in metafile, pdf and eps. as_chunks gives fixed-size arrays, so the loops read the same bytes without indexing into slices, and encrypt's CBC loop takes the remainder from as_chunks instead of the iterator. as_chunks is stable since 1.88. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01U9TrG4w49oSRYbP3cqxA3D --- crates/eps/src/import/graphics.rs | 6 ++---- crates/metafile/src/dib.rs | 4 ++-- crates/metafile/src/import.rs | 4 ++-- crates/metafile/src/import/emf.rs | 2 +- crates/metafile/src/wmf.rs | 2 +- crates/pdf/src/encrypt.rs | 7 +++---- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/crates/eps/src/import/graphics.rs b/crates/eps/src/import/graphics.rs index 823e2ed9..005a433d 100644 --- a/crates/eps/src/import/graphics.rs +++ b/crates/eps/src/import/graphics.rs @@ -429,10 +429,8 @@ impl Interp<'_> { return Err(PsError::Limit("a path has too many points")); } let mut bp = BezPath::new(); - for r in nums.chunks_exact(4) { - if let [x, y, w, h] = r { - bp.extend(self.rect_path(*x, *y, *w, *h)); - } + for [x, y, w, h] in nums.as_chunks::<4>().0 { + bp.extend(self.rect_path(*x, *y, *w, *h)); } Ok(bp) } diff --git a/crates/metafile/src/dib.rs b/crates/metafile/src/dib.rs index d63e5837..ef98ef15 100644 --- a/crates/metafile/src/dib.rs +++ b/crates/metafile/src/dib.rs @@ -92,7 +92,7 @@ pub(crate) fn rgb24(img: &Rgba, opacity: f32) -> (Vec, Vec) { // Bottom-up: the first stored row is the image's last. let Some(at) = (img.height as usize).checked_sub(y + 1).map(|r| r * row) else { continue }; let Some(dst) = bits.get_mut(at..at + img.width as usize * 3) else { continue }; - for (d, p) in dst.chunks_exact_mut(3).zip(src.as_chunks::<4>().0) { + for (d, p) in dst.as_chunks_mut::<3>().0.iter_mut().zip(src.as_chunks::<4>().0) { let a = (f32::from(p[3]) * opacity.clamp(0.0, 1.0)).round() as u32; d.copy_from_slice(&[over(p[2], a), over(p[1], a), over(p[0], a)]); } @@ -107,7 +107,7 @@ pub(crate) fn bgra32(img: &Rgba, opacity: f32) -> (Vec, Vec) { for (y, src) in img.pixels.chunks_exact(row.max(1)).enumerate() { let Some(at) = (img.height as usize).checked_sub(y + 1).map(|r| r * row) else { continue }; let Some(dst) = bits.get_mut(at..at + row) else { continue }; - for (d, p) in dst.chunks_exact_mut(4).zip(src.as_chunks::<4>().0) { + for (d, p) in dst.as_chunks_mut::<4>().0.iter_mut().zip(src.as_chunks::<4>().0) { let a = (f32::from(p[3]) * opacity.clamp(0.0, 1.0)).round() as u32; let pre = |c: u8| ((u32::from(c) * a + 127) / 255) as u8; d.copy_from_slice(&[pre(p[2]), pre(p[1]), pre(p[0]), a as u8]); diff --git a/crates/metafile/src/import.rs b/crates/metafile/src/import.rs index 482f2293..ecc6a7f1 100644 --- a/crates/metafile/src/import.rs +++ b/crates/metafile/src/import.rs @@ -583,7 +583,7 @@ impl Player { let mut bp = BezPath::new(); bp.move_to(*first); if bezier { - for c in rest.chunks_exact(3) { + for c in rest.as_chunks::<3>().0 { bp.curve_to(c[0], c[1], c[2]); } } else { @@ -636,7 +636,7 @@ impl Player { } }; if bezier { - for c in pts.chunks_exact(3) { + for c in pts.as_chunks::<3>().0 { target.curve_to(xf * c[0], xf * c[1], xf * c[2]); } } else { diff --git a/crates/metafile/src/import/emf.rs b/crates/metafile/src/import/emf.rs index e0eedd01..e2024af2 100644 --- a/crates/metafile/src/import/emf.rs +++ b/crates/metafile/src/import/emf.rs @@ -314,7 +314,7 @@ fn record(p: &mut Player, kind: u32, rec: &[u8]) -> Option<()> { let off = r.u32()?; let s = if kind == 84 { let raw = slice(rec, off, u32::try_from(n.checked_mul(2)?).ok()?)?; - String::from_utf16_lossy(&raw.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect::>()) + String::from_utf16_lossy(&raw.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes(*c)).collect::>()) } else { slice(rec, off, u32::try_from(n).ok()?)?.iter().map(|b| char::from(*b)).collect() }; diff --git a/crates/metafile/src/wmf.rs b/crates/metafile/src/wmf.rs index 5ef36bf0..0e4b82e0 100644 --- a/crates/metafile/src/wmf.rs +++ b/crates/metafile/src/wmf.rs @@ -68,7 +68,7 @@ pub(crate) fn units_per_inch(w: f64, h: f64) -> u16 { /// The XOR of the first ten 16-bit words of a placeable header. pub(crate) fn checksum(header: &[u8]) -> u16 { - header.chunks_exact(2).take(10).fold(0, |acc, w| acc ^ u16::from_le_bytes([w[0], w[1]])) + header.as_chunks::<2>().0.iter().take(10).fold(0, |acc, w| acc ^ u16::from_le_bytes(*w)) } /// `bp` flattened to within `tol`: each subpath's points and whether it closes. diff --git a/crates/pdf/src/encrypt.rs b/crates/pdf/src/encrypt.rs index 173f1de5..39a9ff48 100644 --- a/crates/pdf/src/encrypt.rs +++ b/crates/pdf/src/encrypt.rs @@ -232,12 +232,11 @@ impl Aes { prev = self.block(std::array::from_fn(|i| chunk[i] ^ prev[i])); out.extend_from_slice(&prev); }; - let mut chunks = data.chunks_exact(16); - for c in &mut chunks { - put(std::array::from_fn(|i| c.get(i).copied().unwrap_or_default()), &mut out); + let (chunks, rest) = data.as_chunks::<16>(); + for c in chunks { + put(*c, &mut out); } if pad { - let rest = chunks.remainder(); let n = (16 - rest.len()) as u8; put(std::array::from_fn(|i| rest.get(i).copied().unwrap_or(n)), &mut out); }