From 5d31deeae43e8f3803604f837649bbaeb625e726 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 11 Jul 2015 14:05:56 +0530 Subject: [PATCH] Add error explanation for E0017 --- src/librustc/diagnostics.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 75d94cdffb1..4aac09e02b7 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -306,6 +306,28 @@ const FOO: i32 = { const X : i32 = 0; X }; ``` "##, +E0017: r##" +References in statics and constants may only refer to immutable values. Example: + +``` +static X: i32 = 1; +const C: i32 = 2; + +// these three are not allowed: +const CR: &'static mut i32 = &mut C; +static STATIC_REF: &'static mut i32 = &mut X; +static CONST_REF: &'static mut i32 = &mut C; +``` + +Statics are shared everywhere, and if they refer to mutable data one might +violate memory safety since holding multiple mutable references to shared data +is not allowed. + +If you really want global mutable state, try using a global `UnsafeCell` or +`static mut`. + +"##, + E0018: r##" The value of static and const variables must be known at compile time. You can't cast a pointer as an integer because we can't know what value the @@ -1255,7 +1277,6 @@ contain references (with a maximum lifetime of `'a`). register_diagnostics! { // E0006 // merged with E0005 - E0017, E0022, E0038, // E0134,