Email me

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.

E0625Const, static and compile-time
Activein rustc 1.99.0
5related errors linked below

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

All 518 Rust error codes · Rust crate data · Glossary

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?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ