]> git.lizzy.rs Git - rust.git/blob - src/docs/redundant_else.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / redundant_else.txt
1 ### What it does
2 Checks for `else` blocks that can be removed without changing semantics.
3
4 ### Why is this bad?
5 The `else` block adds unnecessary indentation and verbosity.
6
7 ### Known problems
8 Some may prefer to keep the `else` block for clarity.
9
10 ### Example
11 ```
12 fn my_func(count: u32) {
13     if count == 0 {
14         print!("Nothing to do");
15         return;
16     } else {
17         print!("Moving on...");
18     }
19 }
20 ```
21 Use instead:
22 ```
23 fn my_func(count: u32) {
24     if count == 0 {
25         print!("Nothing to do");
26         return;
27     }
28     print!("Moving on...");
29 }
30 ```