-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
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` onceIf 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)
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy