From 37a84bc82169bfdd0c67c519e710ba4488b82d55 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 11 Jul 2015 14:13:25 +0530 Subject: [PATCH] Add error explanation for E0022 --- src/librustc/diagnostics.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 4aac09e02b7f..0375f64d7a50 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,