RS.CLIPPY.INSPECT_FOR_EACH
Using `.inspect().for_each()`, which can be replaced with `.for_each()`
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: inspect_for_each. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for usage of inspect().for_each().
Why is this bad?
It is the same as performing the computation
inside inspect at the beginning of the closure in for_each.
Example
[1,2,3,4,5].iter()
.inspect(|&x| println!("inspect the number: {}", x))
.for_each(|&x| {
assert!(x >= 0);
});
Can be written as
[1,2,3,4,5].iter()
.for_each(|&x| {
println!("inspect the number: {}", x);
assert!(x >= 0);
});