about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRuud van Asseldonk <dev@veniogames.com>2015-04-14 20:00:17 +0200
committerRuud van Asseldonk <dev@veniogames.com>2015-04-14 20:00:17 +0200
commitc45eacdbc688708ccd4dd09c8bcfb513e5e5fead (patch)
tree5f6d776cecd2fde6ed87507c72438a8a525e12b5 /src
parent48a376da18b27c787818eec18ad26ba96ebdff67 (diff)
downloadrust-c45eacdbc688708ccd4dd09c8bcfb513e5e5fead.tar.gz
rust-c45eacdbc688708ccd4dd09c8bcfb513e5e5fead.zip
rustc: Add long diagnostics for E0162
Diffstat (limited to 'src')
-rw-r--r--src/librustc/diagnostics.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs
index 7f77c0fceea..d4a1dd26660 100644
--- a/src/librustc/diagnostics.rs
+++ b/src/librustc/diagnostics.rs
@@ -112,6 +112,25 @@ reference when using guards or refactor the entire expression, perhaps by
 putting the condition inside the body of the arm.
 "##,
 
+E0162: r##"
+An if-let pattern attempts to match the pattern, and enters the body if the
+match was succesful. 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.
+    foo(x);
+}
+
+// Try this instead:
+let Irrefutable(x) = irr;
+foo(x);
+"##,
+
 E0297: r##"
 Patterns used to bind names must be irrefutable. That is, they must guarantee
 that a name will be extracted in all cases. Instead of pattern matching the
@@ -220,7 +239,6 @@ register_diagnostics! {
     E0152,
     E0158,
     E0161,
-    E0162,
     E0165,
     E0170,
     E0261, // use of undeclared lifetime name