about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-07-11 14:13:25 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-07-23 12:47:05 +0530
commit37a84bc82169bfdd0c67c519e710ba4488b82d55 (patch)
treec7c6d2f5397666ff5c04eaed9a9d9bde8e5ce6ee
parent5d31deeae43e8f3803604f837649bbaeb625e726 (diff)
downloadrust-37a84bc82169bfdd0c67c519e710ba4488b82d55.tar.gz
rust-37a84bc82169bfdd0c67c519e710ba4488b82d55.zip
Add error explanation for E0022
-rw-r--r--src/librustc/diagnostics.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs
index 4aac09e02b7..0375f64d7a5 100644
--- a/src/librustc/diagnostics.rs
+++ b/src/librustc/diagnostics.rs
@@ -375,7 +375,7 @@ fn main() {
 ```
 
 Remember: you can't use a function call inside a const's initialization
-expression! However, you can totally use it elsewhere you want:
+expression! However, you can totally use it anywhere else:
 
 ```
 fn main() {
@@ -392,6 +392,24 @@ This error indicates that an attempt was made to divide by zero (or take the
 remainder of a zero divisor) in a static or constant expression.
 "##,
 
+E0022: r##"
+Constant functions are not allowed to mutate anything. Thus, binding to an
+argument with a mutable pattern is not allowed. For example,
+
+```
+const fn foo(mut x: u8) {
+    // do stuff
+}
+```
+
+is bad because the function body may not mutate `x`.
+
+Remove any mutable bindings from the argument list to fix this error. In case
+you need to mutate the argument, try lazily initializing a global variable
+instead of using a const fn, or refactoring the code to a functional style to
+avoid mutation if possible.
+"##,
+
 E0030: r##"
 When matching against a range, the compiler verifies that the range is
 non-empty.  Range patterns include both end-points, so this is equivalent to
@@ -1277,7 +1295,6 @@ contain references (with a maximum lifetime of `'a`).
 
 register_diagnostics! {
     // E0006 // merged with E0005
-    E0022,
     E0038,
 //  E0134,
 //  E0135,