Files
rust/tests/ui/never_loop_iterator_reduction.rs
T
Samuel Tardieu 68365697b3 A return in an iterator closure should not trigger never_loop
The iterator never loops when the closure used in, e.g., `.any()`,
panics, not when it diverges as a regular `return` lets the iterator
continue.
2026-01-08 19:45:49 +01:00

25 lines
533 B
Rust

//@no-rustfix
#![warn(clippy::never_loop)]
#![expect(clippy::needless_return)]
fn main() {
// diverging closure with no `return`: should trigger
[0, 1].into_iter().for_each(|x| {
//~^ never_loop
let _ = x;
panic!("boom");
});
// benign closure: should NOT trigger
[0, 1].into_iter().for_each(|x| {
let _ = x + 1;
});
// `return` should NOT trigger even though it is diverging
[0, 1].into_iter().for_each(|x| {
println!("x = {x}");
return;
});
}