@@ -984,6 +984,57 @@ From [RFC 246]:
984
984
[RFC 246]: https://github.com/rust-lang/rfcs/pull/246
985
985
"## ,
986
986
987
+ E0395 : r##"
988
+ The value assigned to a constant expression must be known at compile time,
989
+ which is not the case when comparing raw pointers. Erroneous code example:
990
+
991
+ ```
992
+ static foo: i32 = 42;
993
+ static bar: i32 = 43;
994
+
995
+ static baz: bool = { (&foo as *const i32) == (&bar as *const i32) };
996
+ // error: raw pointers cannot be compared in statics!
997
+ ```
998
+
999
+ Please check that the result of the comparison can be determined at compile time
1000
+ or isn't assigned to a constant expression. Example:
1001
+
1002
+ ```
1003
+ static foo: i32 = 42;
1004
+ static bar: i32 = 43;
1005
+
1006
+ let baz: bool = { (&foo as *const i32) == (&bar as *const i32) };
1007
+ // baz isn't a constant expression so it's ok
1008
+ ```
1009
+ "## ,
1010
+
1011
+ E0396 : r##"
1012
+ The value assigned to a constant expression must be known at compile time,
1013
+ which is not the case when dereferencing raw pointers. Erroneous code
1014
+ example:
1015
+
1016
+ ```
1017
+ const foo: i32 = 42;
1018
+ const baz: *const i32 = (&foo as *const i32);
1019
+
1020
+ const deref: i32 = *baz;
1021
+ // error: raw pointers cannot be dereferenced in constants
1022
+ ```
1023
+
1024
+ To fix this error, please do not assign this value to a constant expression.
1025
+ Example:
1026
+
1027
+ ```
1028
+ const foo: i32 = 42;
1029
+ const baz: *const i32 = (&foo as *const i32);
1030
+
1031
+ unsafe { let deref: i32 = *baz; }
1032
+ // baz isn't a constant expression so it's ok
1033
+ ```
1034
+
1035
+ You'll also note that this assignment must be done in an unsafe block!
1036
+ "## ,
1037
+
987
1038
E0397 : r##"
988
1039
It is not allowed for a mutable static to allocate or have destructors. For
989
1040
example:
@@ -1039,7 +1090,5 @@ register_diagnostics! {
1039
1090
E0314 , // closure outlives stack frame
1040
1091
E0315 , // cannot invoke closure outside of its lifetime
1041
1092
E0316 , // nested quantification of lifetimes
1042
- E0370 , // discriminant overflow
1043
- E0395 , // pointer comparison in const-expr
1044
- E0396 // pointer dereference in const-expr
1093
+ E0370 // discriminant overflow
1045
1094
}
0 commit comments