rust-lang / rust-lang/rust-clippy
`chunks_exact_to_as_chunks` suggests iter() instead of iter_mut() for chunks_exact_mut and does not compile
Open
@cuishuang is already working on this.
Since Aug 21, 2026.
C-bug
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
chunks_exact_to_as_chunks suggests replacing chunks_exact_mut(N) with as_chunks_mut::<N>().0.iter() when it is (almost?) always wrong and does not compile, and should use iter_mut().
The suggestion is also significantly longer and less obvious than the initial code.
Reproducer
Code:
fn main() {
let mut a = vec![1, 2, 3, 4, 5, 6];
a.chunks_exact_mut(2).for_each(|c| c[0] = 2);
}
Current output:
a.as_chunks_mut::<2>().0.iter().for_each(|c| c[0] = 2);
Desired output:
a.as_chunks_mut::<2>().0.iter_mut().for_each(|c| c[0] = 2);
Version
rustc 1.98.0 (88d9e12ae 2026-08-18)
binary: rustc
commit-hash: 88d9e12ae178fab0fb5cc050a94da85685d449ea
commit-date: 2026-08-18
host: x86_64-unknown-linux-gnu
release: 1.98.0
LLVM version: 22.1.8
Additional Labels
@rustbot label +I-suggestion-causes-error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.