]> git.lizzy.rs Git - rust.git/commitdiff
Add long explanation for E0018
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 17 Apr 2015 17:20:47 +0000 (19:20 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Sun, 19 Apr 2015 22:49:53 +0000 (00:49 +0200)
src/librustc/diagnostics.rs

index 306d2cd102fdb8f2456acbf068d3d27b9a041d8f..15e62d2adc2709b3d204b6c45f1dc2b2b80eae4f 100644 (file)
@@ -168,6 +168,29 @@ struct X { x: (), }
 is because Rust currently does not support compile-time function execution.
 "##,
 
+E0018: r##"
+The value of static and const variables must be known at compile time. You
+can't cast a pointer as an integer because we can't know what value the
+address will take.
+
+However, pointers to other constants' address are allowed in constants,
+example:
+
+```
+const X: u32 = 50;
+const Y: *const u32 = &X;
+```
+
+Therefore, casting one of these non-constant pointers to an integer results
+in a non-constant integer whichs lead to this error. Example:
+
+```
+const X: u32 = 50;
+const Y: *const u32 = &X;
+println!("{:?}", Y);
+```
+"##,
+
 E0020: r##"
 This error indicates that an attempt was made to divide by zero (or take the
 remainder of a zero divisor) in a static or constant expression.
@@ -398,7 +421,6 @@ enum Method { GET, POST }
     E0014,
     E0016,
     E0017,
-    E0018,
     E0019,
     E0022,
     E0079, // enum variant: expected signed integer constant