summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/inspect_for_each.txt
blob: 01a46d6c451f4536989dd60becd9d42536cbfa96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
### 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);
});
```