]> git.lizzy.rs Git - rust.git/blob - src/docs/needless_late_init.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / needless_late_init.txt
1 ### What it does
2 Checks for late initializations that can be replaced by a `let` statement
3 with an initializer.
4
5 ### Why is this bad?
6 Assigning in the `let` statement is less repetitive.
7
8 ### Example
9 ```
10 let a;
11 a = 1;
12
13 let b;
14 match 3 {
15     0 => b = "zero",
16     1 => b = "one",
17     _ => b = "many",
18 }
19
20 let c;
21 if true {
22     c = 1;
23 } else {
24     c = -1;
25 }
26 ```
27 Use instead:
28 ```
29 let a = 1;
30
31 let b = match 3 {
32     0 => "zero",
33     1 => "one",
34     _ => "many",
35 };
36
37 let c = if true {
38     1
39 } else {
40     -1
41 };
42 ```