`never_loop`: Also check all known iterator reductions.
Description
never_loop currently only checks loop bodies (loop, while and for), but iterator reduction functions that always diverge are just as likely to be bugs.
fn f(x: i32) -> ! {
panic!();
}
[0, 1].into_iter().for_each(|x| f(x)); // Only calls `f` once
If not looping is actually intended using if let Some(x) = _.next() is much clearer that we do something if any item exists. This suggestion should not be MachineApplicable since looping was likely intended.
fn f(x: i32) -> ! {
panic!();
}
if let Some(x) = [0, 1].into_iter().next() {
f(x);
}
See #16054 for an example of a loop that always diverged without it being immediately obvious. If that were written using for_each instead of a for loop it would still be a bug.
Version
clippy 0.1.93 (6647be9364 2025-11-09)
Hey @Jarcho , this looks like a nice starter task. If you’re not actively on it right now, would you mind if I take a stab at it?
Hi, just following up @Jarcho. Would it be okay if I start a PR for #16061 as my first contribution?
Hello!
I am interested in working on this issue. I am looking to start contributing to the Rust project and this seems like a great entry point for me to learn the codebase and contribution process.
Could I please be assigned this issue?
Thank you!
Hey @Chirag-Janbandhu, just a quick heads‑up: I’ve already started working on this and opened a PR here: #16222 . If you haven’t started yet, you might want to pick another good first issue so we don’t duplicate the same work. But if you’re curious, feel free to check the PR or suggest extra test cases / ideas there. 🙂