Skip to content

Commit 91aa6cf

Browse files
Add better explanations
1 parent 5f20141 commit 91aa6cf

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/librustc/diagnostics.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,26 @@ is because Rust currently does not support compile-time function execution.
169169
"##,
170170

171171
E0018: r##"
172-
The value of static and const variables must be known at compile time, which is
173-
not possible with a pointer or with a value pointed by a pointer.
172+
The value of static and const variables must be known at compile time. You
173+
can't cast an integer as a pointer because we can't know what value will be
174+
at the address.
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+
```
174192
"##,
175193

176194
E0020: r##"

0 commit comments

Comments
 (0)