Rust errors / Const, static and compile-time
Rust compiler error · checked with rustc 1.99.0
Rust error E0625: thread-local statics cannot be accessed at compile-time
What it meansA compile-time const variable is referring to a thread-local static variable.
What rustc prints
error[E0625]: thread-local statics cannot be accessed at compile-time
--> main.rs:6:22
|
6 | const Y: usize = 2 * X;
| ^Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.
The compiler team's explanation
A compile-time const variable is referring to a thread-local static variable.
Erroneous code example:
#![feature(thread_local)]
#[thread_local]
static X: usize = 12;
const Y: usize = 2 * X;
Static and const variables can refer to other const variables but a const variable cannot refer to a thread-local static variable. In this example, Y cannot refer to X. To fix this, the value can be extracted as a const and then used:
#![feature(thread_local)]
const C: usize = 12;
#[thread_local]
static X: usize = C;
const Y: usize = 2 * C;From rustc --explain E0625 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
Up next
Often hit nextE0015: cannot call non-const fn in constantsA related error from the same family.Read it next →Did this answer your question?