]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
1 | Patterns used to bind names must be irrefutable, that is, they must guarantee |
2 | that a name will be extracted in all cases. | |
3 | ||
4 | Erroneous code example: | |
5 | ||
6 | ```compile_fail,E0005 | |
7 | let x = Some(1); | |
8 | let Some(y) = x; | |
9 | // error: refutable pattern in local binding: `None` not covered | |
10 | ``` | |
11 | ||
12 | If you encounter this error you probably need to use a `match` or `if let` to | |
13 | deal with the possibility of failure. Example: | |
14 | ||
15 | ``` | |
16 | let x = Some(1); | |
17 | ||
18 | match x { | |
19 | Some(y) => { | |
20 | // do something | |
21 | }, | |
22 | None => {} | |
23 | } | |
24 | ||
25 | // or: | |
26 | ||
27 | if let Some(y) = x { | |
28 | // do something | |
29 | } | |
30 | ``` |