about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-06-01 10:59:37 +0000
committerbors <bors@rust-lang.org>2015-06-01 10:59:37 +0000
commit3e561f05c00cd180ec02db4ccab2840a4aba93d2 (patch)
tree7aed3ce8b4a2c4829398e982c2c45c73264935b8
parentbaf508ba20d483513b4b5633ff1861d9fc0c92da (diff)
parentdbfc8c5a0711a0746d0af8fdf798f3fc631c83b6 (diff)
downloadrust-3e561f05c00cd180ec02db4ccab2840a4aba93d2.tar.gz
rust-3e561f05c00cd180ec02db4ccab2840a4aba93d2.zip
Auto merge of #25825 - GuillaumeGomez:check_co, r=Manishearth
Part of #24407.
-rw-r--r--src/librustc/diagnostics.rs33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs
index a3577981c1e..5e79e5a5a4e 100644
--- a/src/librustc/diagnostics.rs
+++ b/src/librustc/diagnostics.rs
@@ -176,6 +176,38 @@ for the entire lifetime of a program. Creating a boxed value allocates memory on
 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 @@ static mut BAR: Option<Vec<i32>> = None;
 
 
 register_diagnostics! {
-    E0011,
     E0014,
     E0016,
     E0017,