]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #25825 - GuillaumeGomez:check_co, r=Manishearth
authorbors <bors@rust-lang.org>
Mon, 1 Jun 2015 10:59:37 +0000 (10:59 +0000)
committerbors <bors@rust-lang.org>
Mon, 1 Jun 2015 10:59:37 +0000 (10:59 +0000)
Part of #24407.

src/librustc/diagnostics.rs

index a3577981c1e4b6105b67d2f19e90984e8b29ebea..5e79e5a5a4ed2edf6b1a7623d4ab8bc5b9faf75a 100644 (file)
@@ -176,6 +176,38 @@ struct X { x: (), }
 the heap at runtime, and therefore cannot be done at compile time.
 "##,
 
+E0011: r##"
+Initializers for constants and statics are evaluated at compile time.
+User-defined operators rely on user-defined functions, which cannot be evaluated
+at compile time.
+
+Bad example:
+
+```
+use std::ops::Index;
+
+struct Foo { a: u8 }
+
+impl 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,