]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/collapsible_match.txt
:arrow_up: rust-analyzer
[rust.git] / src / tools / clippy / src / docs / collapsible_match.txt
1 ### What it does
2 Finds nested `match` or `if let` expressions where the patterns may be "collapsed" together
3 without adding any branches.
4
5 Note that this lint is not intended to find _all_ cases where nested match patterns can be merged, but only
6 cases where merging would most likely make the code more readable.
7
8 ### Why is this bad?
9 It is unnecessarily verbose and complex.
10
11 ### Example
12 ```
13 fn func(opt: Option<Result<u64, String>>) {
14     let n = match opt {
15         Some(n) => match n {
16             Ok(n) => n,
17             _ => return,
18         }
19         None => return,
20     };
21 }
22 ```
23 Use instead:
24 ```
25 fn func(opt: Option<Result<u64, String>>) {
26     let n = match opt {
27         Some(Ok(n)) => n,
28         _ => return,
29     };
30 }
31 ```