]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0625.md
remove trailing newline
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0625.md
1 Static and const variables can refer to other const variables. But a const
2 variable cannot refer to a thread-local static variable.
3
4 Erroneous code example:
5
6 ```compile_fail,E0625
7 #![feature(thread_local)]
8
9 #[thread_local]
10 static X: usize = 12;
11
12 const Y: usize = 2 * X;
13 ```
14
15 In this example, `Y` cannot refer to `X`. To fix this, the value can be
16 extracted as a const and then used:
17
18 ```
19 #![feature(thread_local)]
20
21 const C: usize = 12;
22
23 #[thread_local]
24 static X: usize = C;
25
26 const Y: usize = 2 * C;
27 ```