]> git.lizzy.rs Git - rust.git/blob - src/docs/redundant_closure.txt
Merge commit 'b52fb5234cd7c11ecfae51897a6f7fa52e8777fc' into clippyup
[rust.git] / src / docs / redundant_closure.txt
1 ### What it does
2 Checks for closures which just call another function where
3 the function can be called directly. `unsafe` functions or calls where types
4 get adjusted are ignored.
5
6 ### Why is this bad?
7 Needlessly creating a closure adds code for no benefit
8 and gives the optimizer more work.
9
10 ### Known problems
11 If creating the closure inside the closure has a side-
12 effect then moving the closure creation out will change when that side-
13 effect runs.
14 See [#1439](https://github.com/rust-lang/rust-clippy/issues/1439) for more details.
15
16 ### Example
17 ```
18 xs.map(|x| foo(x))
19 ```
20
21 Use instead:
22 ```
23 // where `foo(_)` is a plain function that takes the exact argument type of `x`.
24 xs.map(foo)
25 ```