Closed
Description
Summary
The double_ended_iterator_last
lint is triggered but using next_back()
instead of last()
would change the behavior of the code because the inspect()
closure mutates a captured variable.
Lint Name
double_ended_iterator_last
Reproducer
I tried this code:
let mut line = 0;
let line_start = memchr::memchr_iter(b'\n', bytes)
.inspect(|_| line += 1)
.last();
I saw this happen:
--> crates/typst-library/src/diag.rs:787:26
|
787 | let line_start = memchr::memchr_iter(b'\n', bytes)
| __________________________^
788 | | .inspect(|_| line += 1)
789 | | .last()
| |______________-----^
| |
| help: try: `next_back()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#double_ended_iterator_last
= note: `-D clippy::double-ended-iterator-last` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::double_ended_iterator_last)]`
I expected to see this happen:
No warning because Iterator::inspect
takes an FnMut closure.
Version
rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1
Additional Labels
No response