diff options
Diffstat (limited to 'compiler/rustc_error_codes/src/error_codes/E0162.md')
-rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0162.md | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0162.md b/compiler/rustc_error_codes/src/error_codes/E0162.md new file mode 100644 index 000000000..0161c9325 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0162.md @@ -0,0 +1,26 @@ +#### Note: this error code is no longer emitted by the compiler. + +An `if let` pattern attempts to match the pattern, and enters the body if the +match was successful. If the match is irrefutable (when it cannot fail to +match), use a regular `let`-binding instead. For instance: + +``` +struct Irrefutable(i32); +let irr = Irrefutable(0); + +// This fails to compile because the match is irrefutable. +if let Irrefutable(x) = irr { + // This body will always be executed. + // ... +} +``` + +Try this instead: + +``` +struct Irrefutable(i32); +let irr = Irrefutable(0); + +let Irrefutable(x) = irr; +println!("{}", x); +``` |