]> git.lizzy.rs Git - rust.git/blob - src/docs/while_let_loop.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / while_let_loop.txt
1 ### What it does
2 Detects `loop + match` combinations that are easier
3 written as a `while let` loop.
4
5 ### Why is this bad?
6 The `while let` loop is usually shorter and more
7 readable.
8
9 ### Known problems
10 Sometimes the wrong binding is displayed ([#383](https://github.com/rust-lang/rust-clippy/issues/383)).
11
12 ### Example
13 ```
14 loop {
15     let x = match y {
16         Some(x) => x,
17         None => break,
18     };
19     // .. do something with x
20 }
21 // is easier written as
22 while let Some(x) = y {
23     // .. do something with x
24 };
25 ```