Closed
Description
// src/lib.rs
pub struct Thing {
pub next: &'static Thing,
}
pub static THING: Thing = Thing { next: &THING };
$ cargo clean
$ RUSTFLAGS=-Zdump-mir= cargo build
error[E0391]: cycle detected when evaluating initializer of static `THING`
--> src/lib.rs:7:1
|
7 | pub static THING: Thing = Thing { next: &THING };
| ^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires caching mir of `THING` for CTFE...
--> src/lib.rs:7:1
|
7 | pub static THING: Thing = Thing { next: &THING };
| ^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires elaborating drops for `THING`...
--> src/lib.rs:7:1
|
7 | pub static THING: Thing = Thing { next: &THING };
| ^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires borrow-checking `THING`...
--> src/lib.rs:7:1
|
7 | pub static THING: Thing = Thing { next: &THING };
| ^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires promoting constants in MIR for `THING`...
--> src/lib.rs:7:1
|
7 | pub static THING: Thing = Thing { next: &THING };
| ^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires const checking `THING`...
--> src/lib.rs:7:1
|
7 | pub static THING: Thing = Thing { next: &THING };
| ^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires building MIR for `THING`...
--> src/lib.rs:7:1
|
7 | pub static THING: Thing = Thing { next: &THING };
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which again requires evaluating initializer of static `THING`, completing the cycle
= note: cycle used when running analysis passes on this crate
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
For more information about this error, try `rustc --explain E0391`.
error: could not compile `repro` (lib) due to 1 previous error
The error does not occur if you build without -Zdump-mir
first.
$ cargo clean
$ cargo build
$ RUSTFLAGS=-Zdump-mir= cargo build
Meta
rustc 1.85.0-nightly (21fe748be 2024-12-11)
binary: rustc
commit-hash: 21fe748be15271ea5804e0507cd699b675efe038
commit-date: 2024-12-11
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5