Skip to content

[ICE]: Expected to find a suitable Fn/FnMut/FnOnce implementation #157951

Description

@matthiaskrgr

snippet:

//@compile-flags: -Znext-solver=globally
fn main() {
    let f = |f: dyn Fn()| f;
    f();
}

Version information

rustc 1.98.0-nightly (01dfd7924 2026-06-15)
binary: rustc
commit-hash: 01dfd79246f1b2d5f146616deff08223a840a9ae
commit-date: 2026-06-15
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.7

Possibly related line of code:

self.call_expr.hir_id,
self.call_expr.span,
method_callee,
);
}
None => {
span_bug!(
self.call_expr.span,
"Expected to find a suitable `Fn`/`FnMut`/`FnOnce` implementation for `{}`",
self.closure_ty
)
}
}

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Znext-solver=globally

Program output

error[E0277]: the size for values of type `(dyn Fn() + 'static)` cannot be known at compilation time
 --> /tmp/icemaker_global_tempdir.kqVr1XkqCxJU/rustc_testrunner_tmpdir_reporting.Baq1EBPw3FbK/mvce.rs:2:17
  |
2 |     let f = |f: dyn Fn()| f;
  |                 ^^^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `(dyn Fn() + 'static)`
  = help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
  |
2 |     let f = |f: &dyn Fn()| f;
  |                 +

error[E0746]: return type cannot be a trait object without pointer indirection
 --> /tmp/icemaker_global_tempdir.kqVr1XkqCxJU/rustc_testrunner_tmpdir_reporting.Baq1EBPw3FbK/mvce.rs:2:27
  |
2 |     let f = |f: dyn Fn()| f;
  |                           ^ doesn't have a size known at compile-time
  |
help: consider returning an `impl Trait` instead of a `dyn Trait`
  |
2 |     let f = |f: dyn Fn()| impl f;
  |                           ++++
help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
  |
2 |     let f = |f: dyn Fn()| Box<dyn Box::new(f>);
  |                           +++++++ +++++++++ ++

error[E0057]: this function takes 1 argument but 0 arguments were supplied
 --> /tmp/icemaker_global_tempdir.kqVr1XkqCxJU/rustc_testrunner_tmpdir_reporting.Baq1EBPw3FbK/mvce.rs:3:5
  |
3 |     f();
  |     ^-- argument #1 of type `(dyn Fn() + 'static)` is missing
  |
note: closure defined here
 --> /tmp/icemaker_global_tempdir.kqVr1XkqCxJU/rustc_testrunner_tmpdir_reporting.Baq1EBPw3FbK/mvce.rs:2:13
  |
2 |     let f = |f: dyn Fn()| f;
  |             ^^^^^^^^^^^^^
help: provide the argument
  |
3 |     f(/* (dyn Fn() + 'static) */);
  |       ++++++++++++++++++++++++++

error: internal compiler error: /rustc-dev/01dfd79246f1b2d5f146616deff08223a840a9ae/compiler/rustc_hir_typeck/src/callee.rs:1164:17: Expected to find a suitable `Fn`/`FnMut`/`FnOnce` implementation for `{closure@/tmp/icemaker_global_tempdir.kqVr1XkqCxJU/rustc_testrunner_tmpdir_reporting.Baq1EBPw3FbK/mvce.rs:2:13: 2:26}`
 --> /tmp/icemaker_global_tempdir.kqVr1XkqCxJU/rustc_testrunner_tmpdir_reporting.Baq1EBPw3FbK/mvce.rs:3:5
  |
3 |     f();
  |     ^^^


thread 'rustc' (2179362) panicked at /rustc-dev/01dfd79246f1b2d5f146616deff08223a840a9ae/compiler/rustc_hir_typeck/src/callee.rs:1164:17:
Box<dyn Any>
stack backtrace:
   0:     0x7f121c2d9a59 - <<std[59c6a60ba8e89306]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[ed07a1efed088ad0]::fmt::Display>::fmt
   1:     0x7f121ca0ebde - core[ed07a1efed088ad0]::fmt::write
   2:     0x7f121c2efe86 - <std[59c6a60ba8e89306]::sys::stdio::unix::Stderr as std[59c6a60ba8e89306]::io::Write>::write_fmt
   3:     0x7f121c2aed4e - std[59c6a60ba8e89306]::panicking::default_hook::{closure#0}
   4:     0x7f121c2cc743 - std[59c6a60ba8e89306]::panicking::default_hook
   5:     0x7f121b0a6d7c - std[59c6a60ba8e89306]::panicking::update_hook::<alloc[8bd4a5f83aeff985]::boxed::Box<rustc_driver_impl[612172d3fffba438]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f121c2cca22 - std[59c6a60ba8e89306]::panicking::panic_with_hook
   7:     0x7f121b0d4a01 - std[59c6a60ba8e89306]::panicking::begin_panic::<rustc_errors[99fb5a7ca76c9109]::ExplicitBug>::{closure#0}
   8:     0x7f121b0cd776 - std[59c6a60ba8e89306]::sys::backtrace::__rust_end_short_backtrace::<std[59c6a60ba8e89306]::panicking::begin_panic<rustc_errors[99fb5a7ca76c9109]::ExplicitBug>::{closure#0}, !>
   9:     0x7f121b0cb707 - std[59c6a60ba8e89306]::panicking::begin_panic::<rustc_errors[99fb5a7ca76c9109]::ExplicitBug>
  10:     0x7f121b0dfb21 - <rustc_errors[99fb5a7ca76c9109]::diagnostic::BugAbort as rustc_errors[99fb5a7ca76c9109]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f121b74be2c - <rustc_errors[99fb5a7ca76c9109]::DiagCtxtHandle>::span_bug::<rustc_span[d4fd5768c485f4c5]::span_encoding::Span, alloc[8bd4a5f83aeff985]::string::String>
  12:     0x7f121b776aa6 - rustc_middle[67f6af85fdf6e9f0]::util::bug::opt_span_bug_fmt::<rustc_span[d4fd5768c485f4c5]::span_encoding::Span>::{closure#0}
  13:     0x7f121b776c32 - rustc_middle[67f6af85fdf6e9f0]::ty::context::tls::with_opt::<rustc_middle[67f6af85fdf6e9f0]::util::bug::opt_span_bug_fmt<rustc_span[d4fd5768c485f4c5]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7f121b765dbb - rustc_middle[67f6af85fdf6e9f0]::ty::context::tls::with_context_opt::<rustc_middle[67f6af85fdf6e9f0]::ty::context::tls::with_opt<rustc_middle[67f6af85fdf6e9f0]::util::bug::opt_span_bug_fmt<rustc_span[d4fd5768c485f4c5]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7f1218f83fc8 - rustc_middle[67f6af85fdf6e9f0]::util::bug::span_bug_fmt::<rustc_span[d4fd5768c485f4c5]::span_encoding::Span>
  16:     0x7f121d743a89 - <rustc_hir_typeck[38aac02dd9f6e794]::fn_ctxt::FnCtxt>::analyze_closure
  17:     0x7f121cfe85a6 - <rustc_hir_typeck[38aac02dd9f6e794]::upvar::InferBorrowKindVisitor as rustc_hir[859c213da54473a]::intravisit::Visitor>::visit_expr
  18:     0x7f121cfe8425 - <rustc_hir_typeck[38aac02dd9f6e794]::upvar::InferBorrowKindVisitor as rustc_hir[859c213da54473a]::intravisit::Visitor>::visit_block
  19:     0x7f121cfddbcb - rustc_hir_typeck[38aac02dd9f6e794]::typeck_with_inspect::{closure#0}
  20:     0x7f121cfda530 - rustc_query_impl[442a6da4cb289e52]::query_impl::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
  21:     0x7f121cfd9aa6 - rustc_query_impl[442a6da4cb289e52]::execution::try_execute_query::<rustc_data_structures[f9b58af056a886a2]::vec_cache::VecCache<rustc_span[d4fd5768c485f4c5]::def_id::LocalDefId, rustc_middle[67f6af85fdf6e9f0]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[67f6af85fdf6e9f0]::dep_graph::graph::DepNodeIndex>, false>
  22:     0x7f121cfd9503 - rustc_query_impl[442a6da4cb289e52]::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
  23:     0x7f121cfd3e97 - <rustc_middle[67f6af85fdf6e9f0]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[22d29cf3288c9316]::check_crate::{closure#1}>::{closure#0}
  24:     0x7f121cfd386f - rustc_hir_analysis[22d29cf3288c9316]::check_crate
  25:     0x7f121cfd5b8c - rustc_interface[679c31579adae330]::passes::analysis
  26:     0x7f121dc13806 - rustc_query_impl[442a6da4cb289e52]::execution::try_execute_query::<rustc_middle[67f6af85fdf6e9f0]::query::caches::SingleCache<rustc_middle[67f6af85fdf6e9f0]::query::erase::ErasedData<[u8; 0usize]>>, false>
  27:     0x7f121dc134e9 - rustc_query_impl[442a6da4cb289e52]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  28:     0x7f121dc44317 - rustc_interface[679c31579adae330]::interface::run_compiler::<(), rustc_driver_impl[612172d3fffba438]::run_compiler::{closure#0}>::{closure#1}
  29:     0x7f121dc06e3a - std[59c6a60ba8e89306]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[679c31579adae330]::util::run_in_thread_with_globals<rustc_interface[679c31579adae330]::util::run_in_thread_pool_with_globals<rustc_interface[679c31579adae330]::interface::run_compiler<(), rustc_driver_impl[612172d3fffba438]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  30:     0x7f121dc06bed - <std[59c6a60ba8e89306]::thread::lifecycle::spawn_unchecked<rustc_interface[679c31579adae330]::util::run_in_thread_with_globals<rustc_interface[679c31579adae330]::util::run_in_thread_pool_with_globals<rustc_interface[679c31579adae330]::interface::run_compiler<(), rustc_driver_impl[612172d3fffba438]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[ed07a1efed088ad0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  31:     0x7f121dbfd090 - <std[59c6a60ba8e89306]::sys::thread::unix::Thread>::new::thread_start
  32:     0x7f12170981b9 - <unknown>
  33:     0x7f121711d21c - <unknown>
  34:                0x0 - <unknown>

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.98.0-nightly (01dfd7924 2026-06-15) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z next-solver=globally -Z dump-mir-dir=dir

query stack during panic:
#0 [typeck_root] type-checking `main`
#1 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0057, E0277, E0746.
For more information about an error, try `rustc --explain E0057`.

@rustbot label +WG-trait-system-refactor

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-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.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions