Skip to content

Commit 1ade076

Browse files
committed
Auto merge of #26029 - GuillaumeGomez:const_check, r=Manishearth
Part of #24407.
2 parents bea1c4a + ae550bd commit 1ade076

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/librustc/diagnostics.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,25 @@ const Y: i32 = A;
227227
```
228228
"##,
229229

230+
E0014: r##"
231+
Constants can only be initialized by a constant value or, in a future
232+
version of Rust, a call to a const function. This error indicates the use
233+
of a path (like a::b, or x) denoting something other than one of these
234+
allowed items. Example:
235+
236+
```
237+
const FOO: i32 = { let x = 0; x }; // 'x' isn't a constant nor a function!
238+
```
239+
240+
To avoid it, you have to replace the non-constant value:
241+
242+
```
243+
const FOO: i32 = { const X : i32 = 0; X };
244+
// or even:
245+
const FOO: i32 = { 0 }; // but brackets are useless here
246+
```
247+
"##,
248+
230249
E0015: r##"
231250
The only functions that can be called in static or constant expressions are
232251
`const` functions. Rust currently does not support more general compile-time
@@ -931,7 +950,6 @@ static mut BAR: Option<Vec<i32>> = None;
931950

932951

933952
register_diagnostics! {
934-
E0014,
935953
E0016,
936954
E0017,
937955
E0019,

0 commit comments

Comments
 (0)