]> git.proxmox.com Git - rustc.git/blob - src/librustc_error_codes/error_codes/E0019.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0019.md
1 A function call isn't allowed in the const's initialization expression
2 because the expression's value must be known at compile-time.
3
4 Erroneous code example:
5
6 ```compile_fail,E0019
7 #![feature(box_syntax)]
8
9 fn main() {
10 struct MyOwned;
11
12 static STATIC11: Box<MyOwned> = box MyOwned; // error!
13 }
14 ```
15
16 Remember: you can't use a function call inside a const's initialization
17 expression! However, you can totally use it anywhere else:
18
19 ```
20 enum Test {
21 V1
22 }
23
24 impl Test {
25 fn func(&self) -> i32 {
26 12
27 }
28 }
29
30 fn main() {
31 const FOO: Test = Test::V1;
32
33 FOO.func(); // here is good
34 let x = FOO.func(); // or even here!
35 }
36 ```