chore(lint): use as_chunks for constant-size slice chunking #322

Merged
jqueuniet merged 1 commit from chore/clippy-as-chunks into main 2026-09-05 06:51:12 +02:00
Owner

clippy 1.98 fires chunks_exact_to_as_chunks on every chunks_exact(N) with a
constant N — 19 sites across eight files in five crates. rust:1-trixie, the
image CI's stable job uses, ships 1.98.0 today, so this goes red as soon as
the runner pulls that tag again.

Not just cosmetic

as_chunks yields &[T; N] rather than &[T], so the try_into().unwrap() /
try_into().expect(...) pairs that turned each chunk back into an array
disappear at five sites:

-    bytes.chunks_exact(2).map(move |chunk| {
-        let bytes2: [u8; 2] = chunk.try_into().expect("chunks_exact(2)");
+    bytes.as_chunks::<2>().0.iter().map(move |&bytes2| ...

Behaviour is unchanged

as_chunks drops a trailing partial chunk exactly as chunks_exact does.
transcode_u16_array was the one site consuming chunks.remainder(); it now
takes the remainder from the tuple's second element and still copies the odd
trailing byte through. The impl ExactSizeIterator in public signatures still
holds, since slice::Iter is one.

convert.rs keeps its remaining chunks_exact(size) — that one chunks by a
runtime parameter, which as_chunks cannot express and the lint does not flag.

MSRV

as_chunks and as_chunks_mut are both stable since 1.88, under the 1.90
floor. Verified by running cargo +1.90 check --workspace --all-targets --locked in the CI image, not just by reading the stability attributes.

Checks

cargo fmt --check, cargo clippy --workspace --all-targets -D warnings
(clean), cargo test --workspace --locked (132 suites, 1249 passed, 0 failed),
cargo doc with warnings denied.

No CHANGELOG entry: this is an internal refactor with no user-visible effect,
and touching the Unreleased section here would conflict with #321.

clippy 1.98 fires `chunks_exact_to_as_chunks` on every `chunks_exact(N)` with a constant `N` — 19 sites across eight files in five crates. `rust:1-trixie`, the image CI's `stable` job uses, ships 1.98.0 today, so this goes red as soon as the runner pulls that tag again. ## Not just cosmetic `as_chunks` yields `&[T; N]` rather than `&[T]`, so the `try_into().unwrap()` / `try_into().expect(...)` pairs that turned each chunk back into an array disappear at five sites: ```rust - bytes.chunks_exact(2).map(move |chunk| { - let bytes2: [u8; 2] = chunk.try_into().expect("chunks_exact(2)"); + bytes.as_chunks::<2>().0.iter().map(move |&bytes2| ... ``` ## Behaviour is unchanged `as_chunks` drops a trailing partial chunk exactly as `chunks_exact` does. `transcode_u16_array` was the one site consuming `chunks.remainder()`; it now takes the remainder from the tuple's second element and still copies the odd trailing byte through. The `impl ExactSizeIterator` in public signatures still holds, since `slice::Iter` is one. `convert.rs` keeps its remaining `chunks_exact(size)` — that one chunks by a runtime parameter, which `as_chunks` cannot express and the lint does not flag. ## MSRV `as_chunks` and `as_chunks_mut` are both stable since 1.88, under the 1.90 floor. Verified by running `cargo +1.90 check --workspace --all-targets --locked` in the CI image, not just by reading the stability attributes. ## Checks `cargo fmt --check`, `cargo clippy --workspace --all-targets -D warnings` (clean), `cargo test --workspace --locked` (132 suites, 1249 passed, 0 failed), `cargo doc` with warnings denied. No CHANGELOG entry: this is an internal refactor with no user-visible effect, and touching the `Unreleased` section here would conflict with #321.
chore(lint): use as_chunks for constant-size slice chunking
All checks were successful
CI / msrv (1.90) (pull_request) Successful in 51s
CI / audit (pull_request) Successful in 19s
CI / stable (pull_request) Successful in 1m19s
CI / python bindings (3.11) (pull_request) Successful in 33s
CI / msrv (1.90) (push) Successful in 1m6s
CI / stable (push) Successful in 1m21s
CI / audit (push) Successful in 13s
CI / python bindings (3.11) (push) Successful in 31s
669a9d5c3f
clippy 1.98 fires `chunks_exact_to_as_chunks` on every `chunks_exact(N)`
with a constant N, 19 sites across eight files. The suggestion is not just
cosmetic: `as_chunks` yields `&[T; N]` rather than `&[T]`, so the
`try_into().unwrap()` and `try_into().expect(...)` pairs that turned each
chunk back into an array disappear at five of them.

Behaviour is unchanged. `as_chunks` drops a trailing partial chunk exactly
as `chunks_exact` does; `transcode_u16_array`, the one site that consumed
`chunks.remainder()`, now takes the remainder from the tuple's second
element and still copies the odd trailing byte through. The iterator types
public signatures promise (`impl ExactSizeIterator`) still hold, since
`slice::Iter` is one.

`convert.rs` keeps its remaining `chunks_exact(size)`: that one chunks by a
runtime parameter, which `as_chunks` cannot express and the lint does not
flag.

`as_chunks` and `as_chunks_mut` are both stable since 1.88, under the 1.90
MSRV — verified with `cargo +1.90 check --workspace --all-targets --locked`
in the CI image, not just from the stability attributes.
jqueuniet deleted branch chore/clippy-as-chunks 2026-09-05 06:51:13 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jqueuniet/dm2-tools!322
No description provided.