about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRuud van Asseldonk <dev@veniogames.com>2015-04-14 20:11:04 +0200
committerRuud van Asseldonk <dev@veniogames.com>2015-04-14 20:11:04 +0200
commit33dca5e3ad376e7bd1fd618d5bbd0ed3a27840f8 (patch)
treec40eb9678da49da970a29cc09f5fba188ad2f884
parentc45eacdbc688708ccd4dd09c8bcfb513e5e5fead (diff)
downloadrust-33dca5e3ad376e7bd1fd618d5bbd0ed3a27840f8.tar.gz
rust-33dca5e3ad376e7bd1fd618d5bbd0ed3a27840f8.zip
rustc: Add long diagnostics for E0165
-rw-r--r--src/librustc/diagnostics.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs
index d4a1dd26660..938a74382e2 100644
--- a/src/librustc/diagnostics.rs
+++ b/src/librustc/diagnostics.rs
@@ -131,6 +131,26 @@ let Irrefutable(x) = irr;
 foo(x);
 "##,
 
+E0165: r##"
+A while-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 inside a `loop` instead. For instance:
+
+struct Irrefutable(i32);
+let irr = Irrefutable(0);
+
+// This fails to compile because the match is irrefutable.
+while let Irrefutable(x) = irr {
+    ...
+}
+
+// Try this instead:
+loop {
+    let Irrefutable(x) = irr;
+    ...
+}
+"##,
+
 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
@@ -239,7 +259,6 @@ register_diagnostics! {
     E0152,
     E0158,
     E0161,
-    E0165,
     E0170,
     E0261, // use of undeclared lifetime name
     E0262, // illegal lifetime parameter name