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