From 47c3dc2e7eda06c5637685597359bb23939cbfe4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 24 Jun 2015 20:45:22 +0200 Subject: [PATCH] Add E0395 error explanation --- src/librustc_typeck/diagnostics.rs | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 18341af7ea4b..7228501c800c 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,