about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2015-06-24 20:45:22 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2015-06-24 20:49:12 +0200
commit47c3dc2e7eda06c5637685597359bb23939cbfe4 (patch)
tree695b8edfbc3aa933e2dcd73c2c168d964950a5e1
parent4c2587c1c0865dfa04ce7bebb680c2ceec615f5c (diff)
downloadrust-47c3dc2e7eda06c5637685597359bb23939cbfe4.tar.gz
rust-47c3dc2e7eda06c5637685597359bb23939cbfe4.zip
Add E0395 error explanation
-rw-r--r--src/librustc_typeck/diagnostics.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs
index 18341af7ea4..7228501c800 100644
--- a/src/librustc_typeck/diagnostics.rs
+++ b/src/librustc_typeck/diagnostics.rs
@@ -1538,8 +1538,60 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust
 -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!
+"##
+
 }
 
+
 register_diagnostics! {
     E0068,
     E0074,