]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0297.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0297.md
1 #### Note: this error code is no longer emitted by the compiler.
2
3 Patterns used to bind names must be irrefutable. That is, they must guarantee
4 that a name will be extracted in all cases. Instead of pattern matching the
5 loop variable, consider using a `match` or `if let` inside the loop body. For
6 instance:
7
8 ```compile_fail,E0005
9 let xs : Vec<Option<i32>> = vec![Some(1), None];
10
11 // This fails because `None` is not covered.
12 for Some(x) in xs {
13     // ...
14 }
15 ```
16
17 Match inside the loop instead:
18
19 ```
20 let xs : Vec<Option<i32>> = vec![Some(1), None];
21
22 for item in xs {
23     match item {
24         Some(x) => {},
25         None => {},
26     }
27 }
28 ```
29
30 Or use `if let`:
31
32 ```
33 let xs : Vec<Option<i32>> = vec![Some(1), None];
34
35 for item in xs {
36     if let Some(x) = item {
37         // ...
38     }
39 }
40 ```