summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/manual_flatten.txt
blob: 62d5f3ec9357659152c99389be9f436c791a6a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
### What it does
Check for unnecessary `if let` usage in a for loop
where only the `Some` or `Ok` variant of the iterator element is used.

### Why is this bad?
It is verbose and can be simplified
by first calling the `flatten` method on the `Iterator`.

### Example

```
let x = vec![Some(1), Some(2), Some(3)];
for n in x {
    if let Some(n) = n {
        println!("{}", n);
    }
}
```
Use instead:
```
let x = vec![Some(1), Some(2), Some(3)];
for n in x.into_iter().flatten() {
    println!("{}", n);
}
```