]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0162.md
Merge commit '61667dedf55e3e5aa584f7ae2bd0471336b92ce9' into sync_cg_clif-2021-09-19
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0162.md
1 #### Note: this error code is no longer emitted by the compiler.
2
3 An `if let` pattern attempts to match the pattern, and enters the body if the
4 match was successful. If the match is irrefutable (when it cannot fail to
5 match), use a regular `let`-binding instead. For instance:
6
7 ```
8 struct Irrefutable(i32);
9 let irr = Irrefutable(0);
10
11 // This fails to compile because the match is irrefutable.
12 if let Irrefutable(x) = irr {
13     // This body will always be executed.
14     // ...
15 }
16 ```
17
18 Try this instead:
19
20 ```
21 struct Irrefutable(i32);
22 let irr = Irrefutable(0);
23
24 let Irrefutable(x) = irr;
25 println!("{}", x);
26 ```