Skip to content

ICE (nightly): entered unreachable code when using closure type name inside impl Foo<Box<dyn FnOnce()>> #146249

@quasardtm

Description

@quasardtm

Code

playground

struct Foo<T>(T);

impl Foo<Box<dyn FnOnce()>> {
    pub fn bar(&self)
    {
        let f = || {};
        dbg!(std::any::type_name_of_val(&f));
    }
}

fn main() {
    let v: Foo<Box<dyn FnOnce()>> = Foo(Box::new(|| {}));
    v.bar();
}

Meta

rustc --version --verbose:

rustc 1.91.0-nightly (a1208bf76 2025-09-03)
binary: rustc
commit-hash: a1208bf765ba783ee4ebdc4c29ab0a0c215806ef
commit-date: 2025-09-03
host: x86_64-pc-windows-msvc
release: 1.91.0-nightly
LLVM version: 21.1.0

stable: Successfully compiled
nightly: Compile error

Error output

thread 'rustc' (31260) panicked at compiler\rustc_const_eval\src\util\type_name.rs:174:18:
internal error: entered unreachable code
Backtrace

stack backtrace:
   0:     0x764ce24770f2 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hb936c33e08ee31b5
   1:     0x764ce2c0c5bc - core::fmt::write::h366f74efd7570b56
   2:     0x764ce242b241 - std::io::Write::write_fmt::he16184c3f94f6129
   3:     0x764ce243c9f2 - std::sys::backtrace::BacktraceLock::print::hf458dd26f6cb58ff
   4:     0x764ce2442cc7 - std::panicking::default_hook::{{closure}}::hedc8fcbbcbd79774
   5:     0x764ce24427d3 - std::panicking::default_hook::h839692eaf7a3cbf4
   6:     0x764ce1465151 - std[e77a9961171f8e6e]::panicking::update_hook::<alloc[cd6d2475bca07d0e]::boxed::Box<rustc_driver_impl[726207b37444496e]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x764ce24431cf - std::panicking::panic_with_hook::h3c36b03f585679af
   8:     0x764ce2442f46 - std::panicking::panic_handler::{{closure}}::h2fd03e9e60a01d9a
   9:     0x764ce243cb39 - std::sys::backtrace::__rust_end_short_backtrace::hf6317f3b75300dce
  10:     0x764ce241c57d - __rustc[2d272aba269decd6]::rust_begin_unwind
  11:     0x764cdf653b80 - core::panicking::panic_fmt::h39b160f6d6d70c8b
  12:     0x764cdedd850c - core::panicking::panic::hfac729911839fe1f
  13:     0x764ce3c65474 - <rustc_const_eval[50680048f3599fc5]::util::type_name::TypeNamePrinter as rustc_middle[f77c94b9b6b5ec22]::ty::print::pretty::PrettyPrinter>::pretty_print_type
  14:     0x764ce3c63dcb - <rustc_const_eval[50680048f3599fc5]::util::type_name::TypeNamePrinter as rustc_middle[f77c94b9b6b5ec22]::ty::print::pretty::PrettyPrinter>::comma_sep::<rustc_middle[f77c94b9b6b5ec22]::ty::generic_args::GenericArg, core[502e31ef4c5fb18d]::iter::adapters::copied::Copied<core[502e31ef4c5fb18d]::slice::iter::Iter<rustc_middle[f77c94b9b6b5ec22]::ty::generic_args::GenericArg>>>
  15:     0x764ce3c64329 - <rustc_const_eval[50680048f3599fc5]::util::type_name::TypeNamePrinter as rustc_middle[f77c94b9b6b5ec22]::ty::print::Printer>::default_print_def_path
  16:     0x764ce3c63dcb - <rustc_const_eval[50680048f3599fc5]::util::type_name::TypeNamePrinter as rustc_middle[f77c94b9b6b5ec22]::ty::print::pretty::PrettyPrinter>::comma_sep::<rustc_middle[f77c94b9b6b5ec22]::ty::generic_args::GenericArg, core[502e31ef4c5fb18d]::iter::adapters::copied::Copied<core[502e31ef4c5fb18d]::slice::iter::Iter<rustc_middle[f77c94b9b6b5ec22]::ty::generic_args::GenericArg>>>
  17:     0x764ce3c64329 - <rustc_const_eval[50680048f3599fc5]::util::type_name::TypeNamePrinter as rustc_middle[f77c94b9b6b5ec22]::ty::print::Printer>::default_print_def_path
  18:     0x764ce3c645f7 - <rustc_const_eval[50680048f3599fc5]::util::type_name::TypeNamePrinter as rustc_middle[f77c94b9b6b5ec22]::ty::print::Printer>::default_print_def_path
  19:     0x764ce3c6408b - <rustc_const_eval[50680048f3599fc5]::util::type_name::TypeNamePrinter as rustc_middle[f77c94b9b6b5ec22]::ty::print::Printer>::default_print_def_path
  20:     0x764ce3c6408b - <rustc_const_eval[50680048f3599fc5]::util::type_name::TypeNamePrinter as rustc_middle[f77c94b9b6b5ec22]::ty::print::Printer>::default_print_def_path
  21:     0x764ce3c63e2b - rustc_const_eval[50680048f3599fc5]::interpret::intrinsics::alloc_type_name
  22:     0x764ce3c6e12f - <rustc_const_eval[50680048f3599fc5]::interpret::eval_context::InterpCx<rustc_const_eval[50680048f3599fc5]::const_eval::machine::CompileTimeMachine>>::eval_intrinsic
  23:     0x764ce3c6cdff - <rustc_const_eval[50680048f3599fc5]::const_eval::machine::CompileTimeMachine as rustc_const_eval[50680048f3599fc5]::interpret::machine::Machine>::call_intrinsic
  24:     0x764ce3c7b50b - <rustc_const_eval[50680048f3599fc5]::interpret::eval_context::InterpCx<rustc_const_eval[50680048f3599fc5]::const_eval::machine::CompileTimeMachine>>::init_fn_call
  25:     0x764ce2f66064 - rustc_const_eval[50680048f3599fc5]::const_eval::eval_queries::eval_to_allocation_raw_provider
  26:     0x764ce2f64d7e - rustc_query_impl[3c2285b51c6e5bea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3c2285b51c6e5bea]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f77c94b9b6b5ec22]::query::erase::Erased<[u8; 24usize]>>
  27:     0x764ce2f491a5 - rustc_query_system[32d702d6a12b7395]::query::plumbing::try_execute_query::<rustc_query_impl[3c2285b51c6e5bea]::DynamicConfig<rustc_query_system[32d702d6a12b7395]::query::caches::DefaultCache<rustc_middle[f77c94b9b6b5ec22]::ty::PseudoCanonicalInput<rustc_middle[f77c94b9b6b5ec22]::mir::interpret::GlobalId>, rustc_middle[f77c94b9b6b5ec22]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[3c2285b51c6e5bea]::plumbing::QueryCtxt, false>
  28:     0x764ce2f48d33 - rustc_query_impl[3c2285b51c6e5bea]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  29:     0x764ce2f4b397 - rustc_const_eval[50680048f3599fc5]::const_eval::eval_queries::eval_to_const_value_raw_provider
  30:     0x764ce2f4b196 - rustc_query_impl[3c2285b51c6e5bea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3c2285b51c6e5bea]::query_impl::eval_to_const_value_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f77c94b9b6b5ec22]::query::erase::Erased<[u8; 24usize]>>
  31:     0x764ce2f4a8c2 - rustc_query_system[32d702d6a12b7395]::query::plumbing::try_execute_query::<rustc_query_impl[3c2285b51c6e5bea]::DynamicConfig<rustc_query_system[32d702d6a12b7395]::query::caches::DefaultCache<rustc_middle[f77c94b9b6b5ec22]::ty::PseudoCanonicalInput<rustc_middle[f77c94b9b6b5ec22]::mir::interpret::GlobalId>, rustc_middle[f77c94b9b6b5ec22]::query::erase::Erased<[u8; 24usize]>>, false, true, false>, rustc_query_impl[3c2285b51c6e5bea]::plumbing::QueryCtxt, false>
  32:     0x764ce2f4a433 - rustc_query_impl[3c2285b51c6e5bea]::query_impl::eval_to_const_value_raw::get_query_non_incr::__rust_end_short_backtrace
  33:     0x764ce3a87b11 - <rustc_middle[f77c94b9b6b5ec22]::ty::context::TyCtxt>::const_eval_resolve
  34:     0x764ce007fa21 - rustc_monomorphize[738c5344c41fe0d4]::collector::items_of_instance
  35:     0x764ce339dcbe - rustc_query_impl[3c2285b51c6e5bea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3c2285b51c6e5bea]::query_impl::items_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f77c94b9b6b5ec22]::query::erase::Erased<[u8; 32usize]>>
  36:     0x764ce33a41cf - rustc_query_system[32d702d6a12b7395]::query::plumbing::try_execute_query::<rustc_query_impl[3c2285b51c6e5bea]::DynamicConfig<rustc_query_system[32d702d6a12b7395]::query::caches::DefaultCache<(rustc_middle[f77c94b9b6b5ec22]::ty::instance::Instance, rustc_middle[f77c94b9b6b5ec22]::mir::mono::CollectionMode), rustc_middle[f77c94b9b6b5ec22]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[3c2285b51c6e5bea]::plumbing::QueryCtxt, false>
  37:     0x764ce33a3de9 - rustc_query_impl[3c2285b51c6e5bea]::query_impl::items_of_instance::get_query_non_incr::__rust_end_short_backtrace
  38:     0x764ce339fb51 - rustc_monomorphize[738c5344c41fe0d4]::collector::collect_items_rec
  39:     0x764ce33a0cb1 - rustc_monomorphize[738c5344c41fe0d4]::collector::collect_items_rec
  40:     0x764ce33a0cb1 - rustc_monomorphize[738c5344c41fe0d4]::collector::collect_items_rec
  41:     0x764ce2e804a1 - rustc_monomorphize[738c5344c41fe0d4]::collector::collect_crate_mono_items::{closure#1}::{closure#0}
  42:     0x764ce356d4d8 - rustc_monomorphize[738c5344c41fe0d4]::partitioning::collect_and_partition_mono_items
  43:     0x764ce40b3724 - rustc_query_impl[3c2285b51c6e5bea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3c2285b51c6e5bea]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f77c94b9b6b5ec22]::query::erase::Erased<[u8; 24usize]>>
  44:     0x764ce40b3709 - <rustc_query_impl[3c2285b51c6e5bea]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[502e31ef4c5fb18d]::ops::function::FnOnce<(rustc_middle[f77c94b9b6b5ec22]::ty::context::TyCtxt, ())>>::call_once
  45:     0x764ce40b3274 - rustc_query_system[32d702d6a12b7395]::query::plumbing::try_execute_query::<rustc_query_impl[3c2285b51c6e5bea]::DynamicConfig<rustc_query_system[32d702d6a12b7395]::query::caches::SingleCache<rustc_middle[f77c94b9b6b5ec22]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[3c2285b51c6e5bea]::plumbing::QueryCtxt, false>
  46:     0x764ce40b3019 - rustc_query_impl[3c2285b51c6e5bea]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  47:     0x764ce3d791ff - <rustc_codegen_llvm[a152390508e65f5b]::LlvmCodegenBackend as rustc_codegen_ssa[4f4749e4f05410ca]::traits::backend::CodegenBackend>::codegen_crate
  48:     0x764ce3ea6770 - <rustc_interface[944ca8d50aecb68a]::queries::Linker>::codegen_and_build_linker
  49:     0x764ce3ea42e7 - rustc_interface[944ca8d50aecb68a]::passes::create_and_enter_global_ctxt::<core[502e31ef4c5fb18d]::option::Option<rustc_interface[944ca8d50aecb68a]::queries::Linker>, rustc_driver_impl[726207b37444496e]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  50:     0x764ce3eb93c5 - rustc_interface[944ca8d50aecb68a]::interface::run_compiler::<(), rustc_driver_impl[726207b37444496e]::run_compiler::{closure#0}>::{closure#1}
  51:     0x764ce3d868c3 - std[e77a9961171f8e6e]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[944ca8d50aecb68a]::util::run_in_thread_with_globals<rustc_interface[944ca8d50aecb68a]::util::run_in_thread_pool_with_globals<rustc_interface[944ca8d50aecb68a]::interface::run_compiler<(), rustc_driver_impl[726207b37444496e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  52:     0x764ce3d86588 - <<std[e77a9961171f8e6e]::thread::Builder>::spawn_unchecked_<rustc_interface[944ca8d50aecb68a]::util::run_in_thread_with_globals<rustc_interface[944ca8d50aecb68a]::util::run_in_thread_pool_with_globals<rustc_interface[944ca8d50aecb68a]::interface::run_compiler<(), rustc_driver_impl[726207b37444496e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[502e31ef4c5fb18d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  53:     0x764ce3d8c875 - std::sys::pal::unix::thread::Thread::new::thread_start::h0933c2bdece7960f
  54:     0x764cdd680aa4 - <unknown>
  55:     0x764cdd70da34 - clone
  56:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: please attach the file at `/playground/rustc-ice-2025-09-05T16_33_19-26.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `core::any::type_name::{constant#0}`
#1 [eval_to_const_value_raw] simplifying constant for the type system `core::any::type_name::{constant#0}`
... and 2 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
error: could not compile `playground` (bin "playground")

Related issue

#145696 #144994

Regression Info (using bisect-rustc)

Regression in nightly-2025-08-18

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-prioritizeIssue: Indicates that prioritization has been requested for this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions