Skip to content

ICE to get the signature of a closure, use 'args.as_closure().sig()' not ''fn_sig()' #150128

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

fn fndef() {
    match () {
        _ if true => || (),
        _ if true => (|| ()) as fn(),
        _ => (|| ()) as unsafe fn(),
    };
}

original:

fn fndef() {
    fn fndef() {}

    match () {
        _ if true => || (),
        _ if true => (|| ()) as fn(),
        _ => (|| ()) as unsafe fn(),
    };
}

Version information

rustc 1.94.0-nightly (ed0006a7b 2025-12-18)
binary: rustc
commit-hash: ed0006a7ba2dc8fabab8ea94d6f843886311b3c7
commit-date: 2025-12-18
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8

Possibly related line of code:

inputs_and_output: Default::default(),
c_variadic: false,
safety: I::Safety::safe(),
abi: I::Abi::rust(),
})
}
ty::Closure(..) => panic!(
"to get the signature of a closure, use `args.as_closure().sig()` not `fn_sig()`",
),
_ => panic!("Ty::fn_sig() called on non-fn type: {:?}", self),
}
}

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.D1pareBrxxi8/rustc_testrunner_tmpdir_reporting.Nl8YBdcxczS3/mvce.rs:7:2
  |
7 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.D1pareBrxxi8/rustc_testrunner_tmpdir_reporting.Nl8YBdcxczS3/mvce.rs`


thread 'rustc' (2332806) panicked at compiler/rustc_type_ir/src/ty_kind.rs:277:32:
to get the signature of a closure, use `args.as_closure().sig()` not `fn_sig()`
stack backtrace:
   0:     0x7fe28540d7c3 - <<std[ba6dda959639dbf0]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[b49faef1907b88c2]::fmt::Display>::fmt
   1:     0x7fe285a10708 - core[b49faef1907b88c2]::fmt::write
   2:     0x7fe285423f36 - <std[ba6dda959639dbf0]::sys::stdio::unix::Stderr as std[ba6dda959639dbf0]::io::Write>::write_fmt
   3:     0x7fe2853e3eb8 - std[ba6dda959639dbf0]::panicking::default_hook::{closure#0}
   4:     0x7fe285401633 - std[ba6dda959639dbf0]::panicking::default_hook
   5:     0x7fe2843f2027 - std[ba6dda959639dbf0]::panicking::update_hook::<alloc[62e895731fd8cffb]::boxed::Box<rustc_driver_impl[b124cba3b125adad]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fe285401912 - std[ba6dda959639dbf0]::panicking::panic_with_hook
   7:     0x7fe2853e3faa - std[ba6dda959639dbf0]::panicking::panic_handler::{closure#0}
   8:     0x7fe2853d8809 - std[ba6dda959639dbf0]::sys::backtrace::__rust_end_short_backtrace::<std[ba6dda959639dbf0]::panicking::panic_handler::{closure#0}, !>
   9:     0x7fe2853e5b2d - __rustc[1356cd100018542f]::rust_begin_unwind
  10:     0x7fe28252ab4c - core[b49faef1907b88c2]::panicking::panic_fmt
  11:     0x7fe285a479cb - <rustc_middle[69300f9e41224d25]::ty::Ty>::fn_sig
  12:     0x7fe28709e4fe - <rustc_borrowck[83230c1e3a5b0c9d]::type_check::TypeChecker as rustc_middle[69300f9e41224d25]::mir::visit::Visitor>::visit_body
  13:     0x7fe282d02e62 - rustc_borrowck[83230c1e3a5b0c9d]::type_check::type_check
  14:     0x7fe286b381bf - <rustc_borrowck[83230c1e3a5b0c9d]::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
  15:     0x7fe286b31390 - rustc_query_impl[83b8aecbfd85ea07]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[83b8aecbfd85ea07]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[69300f9e41224d25]::query::erase::Erased<[u8; 8usize]>>
  16:     0x7fe285af4577 - rustc_query_system[e7c78e1cc47b3dd8]::query::plumbing::try_execute_query::<rustc_query_impl[83b8aecbfd85ea07]::DynamicConfig<rustc_data_structures[129a2c796af27521]::vec_cache::VecCache<rustc_span[eb9fcd3b7b0f9843]::def_id::LocalDefId, rustc_middle[69300f9e41224d25]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[e7c78e1cc47b3dd8]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[83b8aecbfd85ea07]::plumbing::QueryCtxt, false>
  17:     0x7fe285af8819 - rustc_query_impl[83b8aecbfd85ea07]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  18:     0x7fe285af8a37 - <rustc_middle[69300f9e41224d25]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[6983388c12907c2e]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  19:     0x7fe285af648a - rustc_interface[6983388c12907c2e]::passes::analysis
  20:     0x7fe285af58b3 - rustc_query_impl[83b8aecbfd85ea07]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[83b8aecbfd85ea07]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[69300f9e41224d25]::query::erase::Erased<[u8; 0usize]>>
  21:     0x7fe286bacda6 - rustc_query_system[e7c78e1cc47b3dd8]::query::plumbing::try_execute_query::<rustc_query_impl[83b8aecbfd85ea07]::DynamicConfig<rustc_query_system[e7c78e1cc47b3dd8]::query::caches::SingleCache<rustc_middle[69300f9e41224d25]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[83b8aecbfd85ea07]::plumbing::QueryCtxt, false>
  22:     0x7fe286bac976 - rustc_query_impl[83b8aecbfd85ea07]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7fe286d9ec51 - <rustc_interface[6983388c12907c2e]::passes::create_and_enter_global_ctxt<core[b49faef1907b88c2]::option::Option<rustc_interface[6983388c12907c2e]::queries::Linker>, rustc_driver_impl[b124cba3b125adad]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[b49faef1907b88c2]::ops::function::FnOnce<(&rustc_session[72b8f9ec132a70bd]::session::Session, rustc_middle[69300f9e41224d25]::ty::context::CurrentGcx, alloc[62e895731fd8cffb]::sync::Arc<rustc_data_structures[129a2c796af27521]::jobserver::Proxy>, &std[ba6dda959639dbf0]::sync::once_lock::OnceLock<rustc_middle[69300f9e41224d25]::ty::context::GlobalCtxt>, &rustc_data_structures[129a2c796af27521]::sync::worker_local::WorkerLocal<rustc_middle[69300f9e41224d25]::arena::Arena>, &rustc_data_structures[129a2c796af27521]::sync::worker_local::WorkerLocal<rustc_hir[5d140a9b1caf821b]::Arena>, rustc_driver_impl[b124cba3b125adad]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  24:     0x7fe286b1789a - rustc_interface[6983388c12907c2e]::interface::run_compiler::<(), rustc_driver_impl[b124cba3b125adad]::run_compiler::{closure#0}>::{closure#1}
  25:     0x7fe286b619d2 - std[ba6dda959639dbf0]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[6983388c12907c2e]::util::run_in_thread_with_globals<rustc_interface[6983388c12907c2e]::util::run_in_thread_pool_with_globals<rustc_interface[6983388c12907c2e]::interface::run_compiler<(), rustc_driver_impl[b124cba3b125adad]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  26:     0x7fe286b617a4 - <std[ba6dda959639dbf0]::thread::lifecycle::spawn_unchecked<rustc_interface[6983388c12907c2e]::util::run_in_thread_with_globals<rustc_interface[6983388c12907c2e]::util::run_in_thread_pool_with_globals<rustc_interface[6983388c12907c2e]::interface::run_compiler<(), rustc_driver_impl[b124cba3b125adad]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[b49faef1907b88c2]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27:     0x7fe286b68478 - <std[ba6dda959639dbf0]::sys::thread::unix::Thread>::new::thread_start
  28:     0x7fe28049698b - <unknown>
  29:     0x7fe28051a9cc - <unknown>
  30:                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: rustc 1.94.0-nightly (ed0006a7b 2025-12-18) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `fndef`
#1 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0601`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coercionsArea: implicit and explicit `expr as Type` coercionsC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions