]> git.lizzy.rs Git - rust.git/commitdiff
Add error explanation for E0017
authorManish Goregaokar <manishsmail@gmail.com>
Sat, 11 Jul 2015 08:35:56 +0000 (14:05 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Thu, 23 Jul 2015 07:15:11 +0000 (12:45 +0530)
src/librustc/diagnostics.rs

index 75d94cdffb13db61df179a42bc86081323e0c250..4aac09e02b7fb9b074053a5fc641eb8b4c86098a 100644 (file)
@@ -306,6 +306,28 @@ fn index<'a>(&'a self, idx: u8) -> &'a u8 { &self.a }
 ```
 "##,
 
+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 @@ fn foo<'a>(arg: &Box<SomeTrait+'a>) { ... }
 
 register_diagnostics! {
     // E0006 // merged with E0005
-    E0017,
     E0022,
     E0038,
 //  E0134,