I tried this code:
https://godbolt.org/z/5T4ThrvP8
static C: &'static usize = &(0 | E);
static E: usize = E;
I expected to see this happen: encountered static that tried to access itself during initialization
Instead, this happened:
error[E0080]: encountered static that tried to access itself during initialization
--> <source>:2:19
|
2 | static E: usize = E;
| ^ evaluation of `E` failed here
note: erroneous constant encountered
--> <source>:2:19
|
2 | static E: usize = E;
| ^
error: internal compiler error: /rustc-dev/cced03bfd61a304243a34504618ecec86c17063f/compiler/rustc_const_eval/src/interpret/eval_context.rs:620:33: interpret const eval failure of Unevaluated(UnevaluatedConst { def: DefId(0:3 ~ example[96fa]::C), args: [], promoted: Some(promoted[0]) }, &'{erased} usize) which is not in required_consts
--> <source>:1:28
|
1 | static C: &'static usize = &(0 | E);
| ^^^^^^^^
thread 'rustc' (3) panicked at /rustc-dev/cced03bfd61a304243a34504618ecec86c17063f/compiler/rustc_const_eval/src/interpret/eval_context.rs:620:33:
Box<dyn Any>
stack backtrace:
[... see below]
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: please make sure that you have updated to the latest nightly
note: please attach the file at `/app/rustc-ice-2026-05-30T12_20_03-1.txt` to your bug report
note: rustc 1.98.0-nightly (cced03bfd 2026-05-28) running on x86_64-unknown-linux-gnu
note: compiler flags: -C debuginfo=2 --crate-type rlib
query stack during panic:
#0 [eval_static_initializer] evaluating initializer of static `C`
#1 [analysis] running analysis passes on crate `example`
end of query stack
error: aborting due to 2 previous errors
Meta
rustc --version --verbose:
rustc 1.98.0-nightly (f8a08b688 2026-05-30)
0: 0x748b7409d399 - <<std[929523f510218772]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[28b146924c2f19c6]::fmt::Display>::fmt
1: 0x748b74820608 - core[28b146924c2f19c6]::fmt::write
2: 0x748b740b4086 - <std[929523f510218772]::sys::stdio::unix::Stderr as std[929523f510218772]::io::Write>::write_fmt
3: 0x748b740735be - std[929523f510218772]::panicking::default_hook::{closure#0}
4: 0x748b74090cd3 - std[929523f510218772]::panicking::default_hook
5: 0x748b72e8cde1 - std[929523f510218772]::panicking::update_hook::<alloc[95e62e727ddf147d]::boxed::Box<rustc_driver_impl[9a9e569f729f2f59]::install_ice_hook::{closure#1}>>::{closure#0}
6: 0x748b74090fb2 - std[929523f510218772]::panicking::panic_with_hook
7: 0x748b72ebac41 - std[929523f510218772]::panicking::begin_panic::<rustc_errors[86a14c7986f8b80c]::ExplicitBug>::{closure#0}
8: 0x748b72eb3b26 - std[929523f510218772]::sys::backtrace::__rust_end_short_backtrace::<std[929523f510218772]::panicking::begin_panic<rustc_errors[86a14c7986f8b80c]::ExplicitBug>::{closure#0}, !>
9: 0x748b72eb399b - std[929523f510218772]::panicking::begin_panic::<rustc_errors[86a14c7986f8b80c]::ExplicitBug>
10: 0x748b72ec6121 - <rustc_errors[86a14c7986f8b80c]::diagnostic::BugAbort as rustc_errors[86a14c7986f8b80c]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
11: 0x748b73529b6c - <rustc_errors[86a14c7986f8b80c]::DiagCtxtHandle>::span_bug::<rustc_span[b11df8143abe61b3]::span_encoding::Span, alloc[95e62e727ddf147d]::string::String>
12: 0x748b73555516 - rustc_middle[d3eb09a8c4018225]::util::bug::opt_span_bug_fmt::<rustc_span[b11df8143abe61b3]::span_encoding::Span>::{closure#0}
13: 0x748b735556a2 - rustc_middle[d3eb09a8c4018225]::ty::context::tls::with_opt::<rustc_middle[d3eb09a8c4018225]::util::bug::opt_span_bug_fmt<rustc_span[b11df8143abe61b3]::span_encoding::Span>::{closure#0}, !>::{closure#0}
14: 0x748b7354432b - rustc_middle[d3eb09a8c4018225]::ty::context::tls::with_context_opt::<rustc_middle[d3eb09a8c4018225]::ty::context::tls::with_opt<rustc_middle[d3eb09a8c4018225]::util::bug::opt_span_bug_fmt<rustc_span[b11df8143abe61b3]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
15: 0x748b715a5f18 - rustc_middle[d3eb09a8c4018225]::util::bug::span_bug_fmt::<rustc_span[b11df8143abe61b3]::span_encoding::Span>
16: 0x748b75d694af - rustc_const_eval[b7193a543b04e23a]::const_eval::eval_queries::eval_body_using_ecx::<rustc_middle[d3eb09a8c4018225]::mir::interpret::allocation::ConstAllocation>
17: 0x748b75d1ce75 - rustc_const_eval[b7193a543b04e23a]::const_eval::eval_queries::eval_static_initializer_provider
18: 0x748b75d1c959 - rustc_query_impl[a69af1e3db1aae78]::query_impl::eval_static_initializer::invoke_provider_fn::__rust_begin_short_backtrace
19: 0x748b7496d7c5 - rustc_query_impl[a69af1e3db1aae78]::execution::try_execute_query::<rustc_middle[d3eb09a8c4018225]::query::caches::DefIdCache<rustc_middle[d3eb09a8c4018225]::query::erase::ErasedData<[u8; 16usize]>>, false>
20: 0x748b7502ad4d - rustc_query_impl[a69af1e3db1aae78]::query_impl::eval_static_initializer::execute_query_non_incr::__rust_end_short_backtrace
21: 0x748b7502f648 - <rustc_middle[d3eb09a8c4018225]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[9a1e80da1232f3e9]::check_crate::{closure#1}>::{closure#0}
22: 0x748b7502eea2 - rustc_hir_analysis[9a1e80da1232f3e9]::check_crate
23: 0x748b74d3a0bf - rustc_interface[96f3b8af88022e3c]::passes::analysis
24: 0x748b7599df89 - rustc_query_impl[a69af1e3db1aae78]::execution::try_execute_query::<rustc_middle[d3eb09a8c4018225]::query::caches::SingleCache<rustc_middle[d3eb09a8c4018225]::query::erase::ErasedData<[u8; 0usize]>>, false>
25: 0x748b7599dbf3 - rustc_query_impl[a69af1e3db1aae78]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
26: 0x748b759ccda9 - rustc_interface[96f3b8af88022e3c]::interface::run_compiler::<(), rustc_driver_impl[9a9e569f729f2f59]::run_compiler::{closure#0}>::{closure#1}
27: 0x748b7598c73c - std[929523f510218772]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[96f3b8af88022e3c]::util::run_in_thread_with_globals<rustc_interface[96f3b8af88022e3c]::util::run_in_thread_pool_with_globals<rustc_interface[96f3b8af88022e3c]::interface::run_compiler<(), rustc_driver_impl[9a9e569f729f2f59]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
28: 0x748b7598ce2d - <std[929523f510218772]::thread::lifecycle::spawn_unchecked<rustc_interface[96f3b8af88022e3c]::util::run_in_thread_with_globals<rustc_interface[96f3b8af88022e3c]::util::run_in_thread_pool_with_globals<rustc_interface[96f3b8af88022e3c]::interface::run_compiler<(), rustc_driver_impl[9a9e569f729f2f59]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[28b146924c2f19c6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
29: 0x748b7598dc2c - <std[929523f510218772]::sys::thread::unix::Thread>::new::thread_start
30: 0x748b6ee94ac3 - <unknown>
31: 0x748b6ef268d0 - <unknown>
32: 0x0 - <unknown>
I tried this code:
https://godbolt.org/z/5T4ThrvP8
I expected to see this happen:
encountered static that tried to access itself during initializationInstead, this happened:
Meta
rustc --version --verbose: