]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/unnecessary_filter_map.txt
Auto merge of #104673 - matthiaskrgr:rollup-85f65ov, r=matthiaskrgr
[rust.git] / src / tools / clippy / src / docs / unnecessary_filter_map.txt
1 ### What it does
2 Checks for `filter_map` calls that could be replaced by `filter` or `map`.
3 More specifically it checks if the closure provided is only performing one of the
4 filter or map operations and suggests the appropriate option.
5
6 ### Why is this bad?
7 Complexity. The intent is also clearer if only a single
8 operation is being performed.
9
10 ### Example
11 ```
12 let _ = (0..3).filter_map(|x| if x > 2 { Some(x) } else { None });
13
14 // As there is no transformation of the argument this could be written as:
15 let _ = (0..3).filter(|&x| x > 2);
16 ```
17
18 ```
19 let _ = (0..4).filter_map(|x| Some(x + 1));
20
21 // As there is no conditional check on the argument this could be written as:
22 let _ = (0..4).map(|x| x + 1);
23 ```