RS.CLIPPY.REDUNDANT_CLOSURE
Redundant closures, i.e., `|a| foo(a)` (which can be written as just `foo`)
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: redundant_closure. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for closures which just call another function where
the function can be called directly. unsafe functions, calls where types
get adjusted or where the callee is marked #[track_caller] are ignored.
Why is this bad?
Needlessly creating a closure adds code for no benefit and gives the optimizer more work.
Known problems
If creating the closure inside the closure has a side- effect then moving the closure creation out will change when that side- effect runs. See #1439 for more details.
Example
xs.map(|x| foo(x))
Use instead:
// where `foo(_)` is a plain function that takes the exact argument type of `x`.
xs.map(foo)