Skip to content

Commit fe11393

Browse files
committed
Auto merge of #24525 - GuillaumeGomez:check-const, r=pnkfelix
Part of #24407.
2 parents 5910dc0 + 737005a commit fe11393

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' addresses 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 which 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.
@@ -413,7 +436,6 @@ register_diagnostics! {
413436
E0014,
414437
E0016,
415438
E0017,
416-
E0018,
417439
E0019,
418440
E0022,
419441
E0079, // enum variant: expected signed integer constant

0 commit comments

Comments
 (0)