Skip to content

Commit 8a6980c

Browse files
Add long explanation for E0018
1 parent 49a94f2 commit 8a6980c

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/librustc/diagnostics.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,29 @@ variant constructors or struct constructors (for unit or tuple structs). This
168168
is because Rust currently does not support compile-time function execution.
169169
"##,
170170

171+
E0018: r##"
172+
The value of static and const variables must be known at compile time. You
173+
can't cast a pointer as an integer because we can't know what value the
174+
address will take.
175+
176+
However, pointers to other constants' address are allowed in constants,
177+
example:
178+
179+
```
180+
const X: u32 = 50;
181+
const Y: *const u32 = &X;
182+
```
183+
184+
Therefore, casting one of these non-constant pointers to an integer results
185+
in a non-constant integer whichs lead to this error. Example:
186+
187+
```
188+
const X: u32 = 50;
189+
const Y: *const u32 = &X;
190+
println!("{:?}", Y);
191+
```
192+
"##,
193+
171194
E0020: r##"
172195
This error indicates that an attempt was made to divide by zero (or take the
173196
remainder of a zero divisor) in a static or constant expression.
@@ -398,7 +421,6 @@ register_diagnostics! {
398421
E0014,
399422
E0016,
400423
E0017,
401-
E0018,
402424
E0019,
403425
E0022,
404426
E0079, // enum variant: expected signed integer constant

0 commit comments

Comments
 (0)