]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/manual_flatten.txt
Auto merge of #101442 - joboet:null_check_tcs, r=thomcc
[rust.git] / src / tools / clippy / src / docs / manual_flatten.txt
1 ### What it does
2 Check for unnecessary `if let` usage in a for loop
3 where only the `Some` or `Ok` variant of the iterator element is used.
4
5 ### Why is this bad?
6 It is verbose and can be simplified
7 by first calling the `flatten` method on the `Iterator`.
8
9 ### Example
10
11 ```
12 let x = vec![Some(1), Some(2), Some(3)];
13 for n in x {
14     if let Some(n) = n {
15         println!("{}", n);
16     }
17 }
18 ```
19 Use instead:
20 ```
21 let x = vec![Some(1), Some(2), Some(3)];
22 for n in x.into_iter().flatten() {
23     println!("{}", n);
24 }
25 ```