]> git.lizzy.rs Git - rust.git/commitdiff
Add E0396 error explanation
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 24 Jun 2015 18:48:12 +0000 (20:48 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 24 Jun 2015 18:55:23 +0000 (20:55 +0200)
src/librustc/diagnostics.rs
src/librustc_typeck/diagnostics.rs

index 0f83cdff5372c95b797e4c3e2870c23b7e6bf6c1..c6b465b47f025aed2733cab72630f7e75448a7a1 100644 (file)
@@ -984,6 +984,57 @@ fn bar(&self) -> i32 { self.0 }
 [RFC 246]: https://github.com/rust-lang/rfcs/pull/246
 "##,
 
+E0395: r##"
+The value assigned to a constant expression must be known at compile time,
+which is not the case when comparing raw pointers. Erroneous code example:
+
+```
+static foo: i32 = 42;
+static bar: i32 = 43;
+
+static baz: bool = { (&foo as *const i32) == (&bar as *const i32) };
+// error: raw pointers cannot be compared in statics!
+```
+
+Please check that the result of the comparison can be determined at compile time
+or isn't assigned to a constant expression. Example:
+
+```
+static foo: i32 = 42;
+static bar: i32 = 43;
+
+let baz: bool = { (&foo as *const i32) == (&bar as *const i32) };
+// baz isn't a constant expression so it's ok
+```
+"##,
+
+E0396: r##"
+The value assigned to a constant expression must be known at compile time,
+which is not the case when dereferencing raw pointers. Erroneous code
+example:
+
+```
+const foo: i32 = 42;
+const baz: *const i32 = (&foo as *const i32);
+
+const deref: i32 = *baz;
+// error: raw pointers cannot be dereferenced in constants!
+```
+
+To fix this error, please do not assign this value to a constant expression.
+Example:
+
+```
+const foo: i32 = 42;
+const baz: *const i32 = (&foo as *const i32);
+
+unsafe { let deref: i32 = *baz; }
+// baz isn't a constant expression so it's ok
+```
+
+You'll also note that this assignment must be done in an unsafe block!
+"##,
+
 E0397: r##"
 It is not allowed for a mutable static to allocate or have destructors. For
 example:
@@ -1039,7 +1090,5 @@ fn bar(&self) -> i32 { self.0 }
     E0314, // closure outlives stack frame
     E0315, // cannot invoke closure outside of its lifetime
     E0316, // nested quantification of lifetimes
-    E0370, // discriminant overflow
-    E0395, // pointer comparison in const-expr
-    E0396  // pointer dereference in const-expr
+    E0370  // discriminant overflow
 }
index 7228501c800c1ab71f5015ef6b2269351be17a9f..d32e194dbd439c061efac02a3d16517dbd7f0216 100644 (file)
@@ -1538,57 +1538,6 @@ impl Baz for Bar { } // Note: This is OK
 -lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
 "##
 
-E0395: r##"
-The value assigned to a constant expression must be known at compile time,
-which is not the case when comparing raw pointers. Erroneous code example:
-
-```
-static foo: i32 = 42;
-static bar: i32 = 43;
-
-static baz: bool = { (&foo as *const i32) == (&bar as *const i32) };
-// error: raw pointers cannot be compared in statics!
-```
-
-To fix this error, please not assign this value to a constant expression.
-Example:
-
-```
-static foo: i32 = 42;
-static bar: i32 = 43;
-
-let baz: bool = { (&foo as *const i32) == (&bar as *const i32) };
-// baz isn't a constant expression so it's ok
-```
-"##,
-
-E0396: r##"
-The value assigned to a constant expression must be known at compile time,
-which is not the case when dereferencing raw pointers. Erroneous code
-example:
-
-```
-const foo: i32 = 42;
-const baz: *const i32 = (&foo as *const i32);
-
-const deref: i32 = *baz;
-// error: raw pointers cannot be dereferenced in constants!
-```
-
-To fix this error, please not assign this value to a constant expression.
-Example:
-
-```
-const foo: i32 = 42;
-const baz: *const i32 = (&foo as *const i32);
-
-unsafe { let deref: i32 = *baz; }
-// baz isn't a constant expression so it's ok
-```
-
-You'll also note that this assignation must be done in an unsafe block!
-"##
-
 }