]> git.lizzy.rs Git - rust.git/commitdiff
Add E0011 explanation
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 29 May 2015 22:44:22 +0000 (00:44 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Sun, 31 May 2015 17:34:03 +0000 (19:34 +0200)
src/librustc/diagnostics.rs

index a3577981c1e4b6105b67d2f19e90984e8b29ebea..4597ae40161dd965c34dfc76c2afcec8a0d47270 100644 (file)
@@ -176,6 +176,38 @@ struct X { x: (), }
 the heap at runtime, and therefore cannot be done at compile time.
 "##,
 
+E0011: r##"
+Using a user-defined operator on const/static variable is restricted to what
+can be evaluated at compile-time. Using an user-defined operator could call a
+user-defined function, which is not allowed.
+
+Bad example:
+
+```
+use std::ops::Index;
+
+struct Foo { a: u8 }
+
+impl ::std::ops::Index<u8> for Foo {
+    type Output = u8;
+
+    fn index<'a>(&'a self, idx: u8) -> &'a u8 { &self.a }
+}
+
+const a: Foo = Foo { a: 0u8 };
+const b: u8 = a[0]; // Index trait is defined by the user, bad!
+```
+
+Only operators on builtin types are allowed.
+
+Example:
+
+```
+const a: &'static [i32] = &[1, 2, 3];
+const b: i32 = a[0]; // Good!
+```
+"##,
+
 E0013: r##"
 Static and const variables can refer to other const variables. But a const
 variable cannot refer to a static variable. For example, `Y` cannot refer to `X`
@@ -899,7 +931,6 @@ fn bar(&self) -> i32 { self.0 }
 
 
 register_diagnostics! {
-    E0011,
     E0014,
     E0016,
     E0017,