rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.89k stars 12.52k forks source link

Panic on missing type on `static` item #130478

Open rakita opened 1 day ago

rakita commented 1 day ago

Code

    pub fn get(&self) -> &KzgSettings {
        match self {
            Self::Default => {
                cfg_if::cfg_if! {
                    if #[cfg(feature = "c-kzg")] {
                        c_kzg::ethereum_kzg_settings()
                    } else if #[cfg(feature = "kzg-rs")] {
                        static DEFAULT = once_cell::race::OnceBox::<KzgSettings>::new();
                        DEFAULT.get_or_init(|| {
                            KzgSettings::load_trusted_setup_file()
                                .expect("failed to load default trusted setup")
                        })
                    } else {
                        unimplemented!()
                    }
                }
            }
            Self::Custom(settings) => settings,
        }
    }

Meta

rustc --version --verbose:

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: aarch64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7

Error output

Panic on `cargo check  --no-default-features --features=kzg-rs`. Backtrace included
Backtrace

``` error: missing type for `static` item --> crates/wiring/src/kzg.rs:31:39 | 31 | static DEFAULT = once_cell::race::OnceBox::::new(); | ^ help: provide a type for the static variable: `: OnceBox` thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/validity.rs:741:21: assertion `left == right` failed left: Mut right: Not stack backtrace: 0: 0x101dc373c - ::fmt::h243268f17d714c7f 1: 0x101e06688 - core::fmt::write::hb3cfb8a30e72d7ff 2: 0x101db9720 - std::io::Write::write_fmt::hfb2314975de9ecf1 3: 0x101dc5c4c - std::panicking::default_hook::{{closure}}::h14c7718ccf39d316 4: 0x101dc5870 - std::panicking::default_hook::hc62e60da3be2f352 5: 0x10b9bc5b8 - as core[f827f14b5e761a5d]::ops::function::Fn<(&dyn for<'a, 'b> core[f827f14b5e761a5d]::ops::function::Fn<(&'a std[4f7d7c3ef984657a]::panic::PanicHookInfo<'b>,), Output = ()> + core[f827f14b5e761a5d]::marker::Sync + core[f827f14b5e761a5d]::marker::Send, &std[4f7d7c3ef984657a]::panic::PanicHookInfo)>>::call 6: 0x101dc6868 - std::panicking::rust_panic_with_hook::h09e8a656f11e82b2 7: 0x101dc6178 - std::panicking::begin_panic_handler::{{closure}}::h1230eb3cc91b241c 8: 0x101dc3bc8 - std::sys::backtrace::__rust_end_short_backtrace::hc3491307aceda2c2 9: 0x101dc5e40 - _rust_begin_unwind 10: 0x101e20ad8 - core::panicking::panic_fmt::ha4b80a05b9fff47a 11: 0x101e20e98 - core::panicking::assert_failed_inner::h57b35cd882aa8c8a 12: 0x10fd230e4 - core[f827f14b5e761a5d]::panicking::assert_failed:: 13: 0x10b8be9fc - rustc_const_eval[21ec315fa1b71203]::interpret::validity::mutability:: 14: 0x10b8bec7c - as rustc_const_eval[21ec315fa1b71203]::interpret::visitor::ValueVisitor>::visit_value 15: 0x10b8bfae0 - as rustc_const_eval[21ec315fa1b71203]::interpret::visitor::ValueVisitor>::walk_value 16: 0x10b8bee70 - as rustc_const_eval[21ec315fa1b71203]::interpret::visitor::ValueVisitor>::visit_value 17: 0x10b8bfae0 - as rustc_const_eval[21ec315fa1b71203]::interpret::visitor::ValueVisitor>::walk_value 18: 0x10b86dcbc - >::validate_operand_internal 19: 0x10b8db56c - rustc_const_eval[21ec315fa1b71203]::const_eval::eval_queries::eval_static_initializer_provider 20: 0x10ce28988 - rustc_query_impl[5e7782f17777a7c9]::plumbing::__rust_begin_short_backtrace::> 21: 0x10ce71414 - >::call_once 22: 0x10cd80fd4 - rustc_query_system[5f1672c0485b57da]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[5e7782f17777a7c9]::plumbing::QueryCtxt, true> 23: 0x10ceb2408 - rustc_query_impl[5e7782f17777a7c9]::query_impl::eval_static_initializer::get_query_incr::__rust_end_short_backtrace 24: 0x10bc38214 - ::run::<(), rustc_data_structures[5fa37262921da6b8]::sync::parallel::disabled::par_for_each_in<&[rustc_span[ab16d476329f5d04]::def_id::LocalDefId], ::par_body_owners::{closure#0}>::{closure#0}::{closure#0}::{closure#0}> 25: 0x10bd5ee80 - rustc_hir_analysis[b55295e9540087c6]::check_crate 26: 0x10c252dc0 - rustc_interface[1340bb505392beac]::passes::analysis 27: 0x10ce2adf8 - rustc_query_impl[5e7782f17777a7c9]::plumbing::__rust_begin_short_backtrace::> 28: 0x10ce798ac - >::call_once 29: 0x10cd90b4c - rustc_query_system[5f1672c0485b57da]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[5e7782f17777a7c9]::plumbing::QueryCtxt, true> 30: 0x10cea28a4 - rustc_query_impl[5e7782f17777a7c9]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace 31: 0x10b9a70b4 - >::enter::, rustc_driver_impl[54c40c94c6cfc0b2]::run_compiler::{closure#0}::{closure#1}::{closure#5}> 32: 0x10b9be1a0 - ::enter::, rustc_span[ab16d476329f5d04]::ErrorGuaranteed>> 33: 0x10b9b298c - >::set::, rustc_driver_impl[54c40c94c6cfc0b2]::run_compiler::{closure#0}>::{closure#1}, core[f827f14b5e761a5d]::result::Result<(), rustc_span[ab16d476329f5d04]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, core[f827f14b5e761a5d]::result::Result<(), rustc_span[ab16d476329f5d04]::ErrorGuaranteed>> 34: 0x10b9bdb34 - rustc_span[ab16d476329f5d04]::create_session_globals_then::, rustc_interface[1340bb505392beac]::util::run_in_thread_with_globals, rustc_driver_impl[54c40c94c6cfc0b2]::run_compiler::{closure#0}>::{closure#1}, core[f827f14b5e761a5d]::result::Result<(), rustc_span[ab16d476329f5d04]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}> 35: 0x10b9db8fc - std[4f7d7c3ef984657a]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[54c40c94c6cfc0b2]::run_compiler::{closure#0}>::{closure#1}, core[f827f14b5e761a5d]::result::Result<(), rustc_span[ab16d476329f5d04]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f827f14b5e761a5d]::result::Result<(), rustc_span[ab16d476329f5d04]::ErrorGuaranteed>> 36: 0x10b9bb7dc - <::spawn_unchecked_, rustc_driver_impl[54c40c94c6cfc0b2]::run_compiler::{closure#0}>::{closure#1}, core[f827f14b5e761a5d]::result::Result<(), rustc_span[ab16d476329f5d04]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f827f14b5e761a5d]::result::Result<(), rustc_span[ab16d476329f5d04]::ErrorGuaranteed>>::{closure#1} as core[f827f14b5e761a5d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 37: 0x101dcefa4 - std::sys::pal::unix::thread::Thread::new::thread_start::h1bd1b9c95010bf71 38: 0x18b536034 - __pthread_joiner_wake error: the compiler unexpectedly panicked. this is a bug. 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: rustc 1.81.0 (eeb90cda1 2024-09-04) running on aarch64-apple-darwin note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED] note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [eval_static_initializer] evaluating initializer of static `kzg::::get::DEFAULT` #1 [analysis] running analysis passes on this crate end of query stack ```

rakita commented 1 day ago

If I add it on both sides it works: static DEFAULT : once_cell::race::OnceBox<KzgSettings> = once_cell::race::OnceBox::new();

saethlin commented 1 day ago

This looks like a duplicate of https://github.com/rust-lang/rust/issues/124164, the fix for which landed on 2024-09-04 and this is reported on nightly-2024-09-04. @rakita Can you check if your reproducer still ICEs on the latest nightly?"

rakita commented 1 day ago

This looks like a duplicate of #124164, the fix for which landed on 2024-09-04 and this is reported on nightly-2024-09-04. @rakita Can you check if your reproducer still ICEs on the latest nightly?"

Cool, it looks like it is the same issue. I will check it later today and close PR