Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Clippy 1.99: use as_chunks for constant-size chunks, and say the gate targets the latest stable

Matthew Farrow75151bd79a8a
diff --git a/crates/affinity/src/container.rs b/crates/affinity/src/container.rs
index 0829f8581..31179a3a0 100644
--- a/crates/affinity/src/container.rs
+++ b/crates/affinity/src/container.rs
@@ -337,7 +337,7 @@ fn unpredict(b: &mut [u8], compression: u8) -> Result<(), Error> {
(0x40, _) => byte_delta(b),
(0x80, false) => {
let mut prev = 0u16;
- for pair in b.chunks_exact_mut(2) {
+ for pair in b.as_chunks_mut::<2>().0.iter_mut() {
let v = u16::from_le_bytes([pair[0], pair[1]]).wrapping_add(prev);
pair.copy_from_slice(&v.to_le_bytes());
prev = v;
@@ -349,7 +349,7 @@ fn unpredict(b: &mut [u8], compression: u8) -> Result<(), Error> {
if b.len() == 0x10000 {
let planes = b.to_vec();
let (hi, lo) = planes.split_at(0x8000);
- for (i, out) in b.chunks_exact_mut(4).enumerate() {
+ for (i, out) in b.as_chunks_mut::<4>().0.iter_mut().enumerate() {
let (Some(h), Some(l)) = (hi.get(2 * i..2 * i + 2), lo.get(2 * i..2 * i + 2)) else {
return Err(Error::Malformed("tile size"));
};
diff --git a/crates/affinity/src/paint.rs b/crates/affinity/src/paint.rs
index 7f08fa518..c4ebff844 100644
--- a/crates/affinity/src/paint.rs
+++ b/crates/affinity/src/paint.rs
@@ -129,7 +129,7 @@ const MAX_STOPS: usize = 1024;
fn floats(v: &Value) -> Option<Vec<f64>> {
match v {
Value::Floats(f) => Some(f.clone()),
- Value::Bytes(b) if b.len() % 4 == 0 => Some(b.chunks_exact(4).map(|c| f64::from(f32::from_le_bytes([c[0], c[1], c[2], c[3]]))).collect()),
+ Value::Bytes(b) if b.len() % 4 == 0 => Some(b.as_chunks::<4>().0.iter().map(|c| f64::from(f32::from_le_bytes(*c))).collect()),
_ => None,
}
}
diff --git a/crates/affinity/src/raster.rs b/crates/affinity/src/raster.rs
index f89aa2627..8cdf9b833 100644
--- a/crates/affinity/src/raster.rs
+++ b/crates/affinity/src/raster.rs
@@ -131,7 +131,7 @@ fn decode(r: &mut Reader, bitmap: ObjId, crop: (u32, u32, u32, u32), world: Affi
f64::from(p.get(i).copied().unwrap_or(0)) / 255.0
}
};
- for (i, px) in rgba.chunks_exact_mut(4).enumerate() {
+ for (i, px) in rgba.as_chunks_mut::<4>().0.iter_mut().enumerate() {
let v: Vec<f64> = planes.iter().map(|p| sample(p, i)).collect();
let (r2, g, b, a) = if channels == 1 {
(v[0], v[0], v[0], 1.0)
diff --git a/crates/effects/src/pixel/tests.rs b/crates/effects/src/pixel/tests.rs
index ff27132e1..dc3d1d04b 100644
--- a/crates/effects/src/pixel/tests.rs
+++ b/crates/effects/src/pixel/tests.rs
@@ -116,7 +116,7 @@ fn every_effect_is_deterministic() {
assert_eq!(a, b, "{id}");
assert_ne!(a, src, "{id} changes the image");
// Premultiplied stays premultiplied.
- assert!(a.chunks_exact(4).all(|p| p[0] <= p[3] && p[1] <= p[3] && p[2] <= p[3]), "{id}");
+ assert!(a.as_chunks::<4>().0.iter().all(|p| p[0] <= p[3] && p[1] <= p[3] && p[2] <= p[3]), "{id}");
}
}
@@ -196,9 +196,9 @@ fn lengths_are_document_units() {
fn gaussian_and_plane_blurs_keep_their_mass() {
let (w, h) = (30, 30);
let mut d = image(w, h, |x, y| if (10..20).contains(&x) && (10..20).contains(&y) { grey(255) } else { [0, 0, 0, 0] });
- let before: u32 = d.chunks_exact(4).map(|p| p[3] as u32).sum();
+ let before: u32 = d.as_chunks::<4>().0.iter().map(|p| p[3] as u32).sum();
gaussian_rgba(&mut d, w, h, 2.0);
- let after: u32 = d.chunks_exact(4).map(|p| p[3] as u32).sum();
+ let after: u32 = d.as_chunks::<4>().0.iter().map(|p| p[3] as u32).sum();
assert!((before as f64 - after as f64).abs() / (before as f64) < 0.02, "{before} → {after}");
assert!(at(&d, w, 9, 15)[3] > 0 && at(&d, w, 10, 15)[3] < 255);
let mut plane: Vec<f32> = (0..w * h).map(|i| if i == 15 * w + 15 { 100.0 } else { 0.0 }).collect();
diff --git a/crates/engine/tests/affinity_corpus.rs b/crates/engine/tests/affinity_corpus.rs
index 2be10b94f..3116088f8 100644
--- a/crates/engine/tests/affinity_corpus.rs
+++ b/crates/engine/tests/affinity_corpus.rs
@@ -48,7 +48,7 @@ fn difference(a: &[u8], b: &[u8]) -> f64 {
[0, 1, 2].map(|i| f64::from(p[i]) * al + 255.0 * (1.0 - al))
};
let (mut sum, mut n) = (0.0, 0usize);
- for (p, q) in a.chunks_exact(4).zip(b.chunks_exact(4)) {
+ for (p, q) in a.as_chunks::<4>().0.iter().zip(b.as_chunks::<4>().0.iter()) {
let (x, y) = (white(p), white(q));
sum += (0..3).map(|i| (x[i] - y[i]).abs()).sum::<f64>();
n += 3;
diff --git a/docs/development.md b/docs/development.md
index e6d1e0922..6e3806f52 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -194,7 +194,9 @@ parameters. Shipped code therefore never panics. Anything that can fail returns
### Enforced by lints
`Cargo.toml` denies these clippy lints for the whole workspace, and `cargo xtask ci` runs clippy with
-`-D warnings`:
+`-D warnings`. The gate targets the current stable Rust (`rust-version` in `Cargo.toml` is only the
+minimum that builds the app, and no toolchain is pinned): when a new stable adds lints, they are fixed
+in the code:
| Banned in shipped code | Use instead |
|---|---|
diff --git a/xtask/src/sha256.rs b/xtask/src/sha256.rs
index ed731dfb8..71cfa396c 100644
--- a/xtask/src/sha256.rs
+++ b/xtask/src/sha256.rs
@@ -19,10 +19,10 @@ pub fn hex(data: &[u8]) -> String {
msg.push(0);
}
msg.extend(bits.to_be_bytes());
- for block in msg.chunks_exact(64) {
+ for block in msg.as_chunks::<64>().0.iter() {
let mut w = [0u32; 64];
- for (i, word) in block.chunks_exact(4).enumerate() {
- w[i] = u32::from_be_bytes([word[0], word[1], word[2], word[3]]);
+ for (i, word) in block.as_chunks::<4>().0.iter().enumerate() {
+ w[i] = u32::from_be_bytes(*word);
}
for i in 16..64 {
let s0 = w[i - 15].rotate_right(7) ^ w[i - 15].rotate_right(18) ^ (w[i - 15] >> 3);