]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/needless_match.txt
:arrow_up: rust-analyzer
[rust.git] / src / tools / clippy / src / docs / needless_match.txt
1 ### What it does
2 Checks for unnecessary `match` or match-like `if let` returns for `Option` and `Result`
3 when function signatures are the same.
4
5 ### Why is this bad?
6 This `match` block does nothing and might not be what the coder intended.
7
8 ### Example
9 ```
10 fn foo() -> Result<(), i32> {
11     match result {
12         Ok(val) => Ok(val),
13         Err(err) => Err(err),
14     }
15 }
16
17 fn bar() -> Option<i32> {
18     if let Some(val) = option {
19         Some(val)
20     } else {
21         None
22     }
23 }
24 ```
25
26 Could be replaced as
27
28 ```
29 fn foo() -> Result<(), i32> {
30     result
31 }
32
33 fn bar() -> Option<i32> {
34     option
35 }
36 ```