Skip to content

[ICE]: async closure as _  #155999

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: --edition=2021
fn needs_fn_mut<T>(x: impl FnMut() -> T) {
    needs_fn_mut(async || x as _)
}

original:

fn needs_fn_mut<T>(x: impl FnMut() -> T) {
    needs_fn_mut(async || x as _)
}

fn main() {}

Version information

rustc 1.97.0-nightly (f53b654a8 2026-04-30)
binary: rustc
commit-hash: f53b654a8882fd5fc036c4ca7a4ff41ce32497a6
commit-date: 2026-04-30
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.4

Possibly related line of code:

match self.coroutine_captures_by_ref_ty().kind() {
ty::FnPtr(sig_tys, _) => sig_tys
.skip_binder()
.visit_with(&mut HasRegionsBoundAt { binder: ty::INNERMOST })
.is_break(),
ty::Error(_) => true,
_ => panic!(),
}
}
}
/// Unlike `has_escaping_bound_vars` or `outermost_exclusive_binder`, this will
/// detect only regions bound *at* the debruijn index.

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --edition=2021

Program output

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

error[E0282]: type annotations needed
 --> /tmp/icemaker_global_tempdir.7aKNqvZVdrhf/rustc_testrunner_tmpdir_reporting.iRHvJdn0oeki/mvce.rs:2:32
  |
2 |     needs_fn_mut(async || x as _)
  |                                ^ cannot infer type


thread 'rustc' (2170575) panicked at /rustc-dev/f53b654a8882fd5fc036c4ca7a4ff41ce32497a6/compiler/rustc_type_ir/src/ty_kind/closure.rs:326:18:
explicit panic
stack backtrace:
   0:     0x7f1e2e2767b9 - <<std[664156f38db6df9a]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[703624273cedab6d]::fmt::Display>::fmt
   1:     0x7f1e2e815f08 - core[703624273cedab6d]::fmt::write
   2:     0x7f1e2e28d1e6 - <std[664156f38db6df9a]::sys::stdio::unix::Stderr as std[664156f38db6df9a]::io::Write>::write_fmt
   3:     0x7f1e2e24c98e - std[664156f38db6df9a]::panicking::default_hook::{closure#0}
   4:     0x7f1e2e269e73 - std[664156f38db6df9a]::panicking::default_hook
   5:     0x7f1e2d260051 - std[664156f38db6df9a]::panicking::update_hook::<alloc[150995461fc6fe17]::boxed::Box<rustc_driver_impl[2526e35b49e1b9f9]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f1e2e26a152 - std[664156f38db6df9a]::panicking::panic_with_hook
   7:     0x7f1e2e24ca84 - std[664156f38db6df9a]::panicking::panic_handler::{closure#0}
   8:     0x7f1e2e240f89 - std[664156f38db6df9a]::sys::backtrace::__rust_end_short_backtrace::<std[664156f38db6df9a]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f1e2e24e4bd - __rustc[574100d523623398]::rust_begin_unwind
  10:     0x7f1e2aee8c9c - core[703624273cedab6d]::panicking::panic_fmt
  11:     0x7f1e2c12ff02 - core[703624273cedab6d]::panicking::panic
  12:     0x7f1e2e0667e7 - <rustc_type_ir[49665286e8605a96]::ty_kind::closure::CoroutineClosureArgs<rustc_middle[5557c243720a2efc]::ty::context::TyCtxt>>::has_self_borrows
  13:     0x7f1e2e888bec - <rustc_trait_selection[a2580856d63937a4]::traits::select::SelectionContext>::candidate_from_obligation_no_cache
  14:     0x7f1e2f893643 - <rustc_trait_selection[a2580856d63937a4]::traits::select::SelectionContext>::poly_select::{closure#0}
  15:     0x7f1e2ef2526d - <rustc_trait_selection[a2580856d63937a4]::traits::fulfill::FulfillProcessor as rustc_data_structures[215040486e66d119]::obligation_forest::ObligationProcessor>::process_obligation
  16:     0x7f1e2e805a90 - <rustc_data_structures[215040486e66d119]::obligation_forest::ObligationForest<rustc_trait_selection[a2580856d63937a4]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[a2580856d63937a4]::traits::fulfill::FulfillProcessor>
  17:     0x7f1e2f16075e - rustc_hir_typeck[39142b598aee5fae]::typeck_with_inspect::{closure#0}
  18:     0x7f1e2f15cf34 - rustc_query_impl[53e4749d94278651]::query_impl::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
  19:     0x7f1e2e9138a6 - rustc_query_impl[53e4749d94278651]::execution::try_execute_query::<rustc_data_structures[215040486e66d119]::vec_cache::VecCache<rustc_span[2d3dd618ebd931a]::def_id::LocalDefId, rustc_middle[5557c243720a2efc]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[5557c243720a2efc]::dep_graph::graph::DepNodeIndex>, false>
  20:     0x7f1e2e9130c3 - rustc_query_impl[53e4749d94278651]::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
  21:     0x7f1e2eb68594 - <rustc_middle[5557c243720a2efc]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[e68f98e97b2f9de6]::check_crate::{closure#1}>::{closure#0}
  22:     0x7f1e2eb67f66 - rustc_hir_analysis[e68f98e97b2f9de6]::check_crate
  23:     0x7f1e2f7669a1 - rustc_interface[952682f9f3d307b7]::passes::analysis
  24:     0x7f1e2f9a0989 - rustc_query_impl[53e4749d94278651]::execution::try_execute_query::<rustc_middle[5557c243720a2efc]::query::caches::SingleCache<rustc_middle[5557c243720a2efc]::query::erase::ErasedData<[u8; 0usize]>>, false>
  25:     0x7f1e2f9a05e9 - rustc_query_impl[53e4749d94278651]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  26:     0x7f1e2f9b7ebc - rustc_interface[952682f9f3d307b7]::interface::run_compiler::<(), rustc_driver_impl[2526e35b49e1b9f9]::run_compiler::{closure#0}>::{closure#1}
  27:     0x7f1e2f99537e - std[664156f38db6df9a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[952682f9f3d307b7]::util::run_in_thread_with_globals<rustc_interface[952682f9f3d307b7]::util::run_in_thread_pool_with_globals<rustc_interface[952682f9f3d307b7]::interface::run_compiler<(), rustc_driver_impl[2526e35b49e1b9f9]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  28:     0x7f1e2f995a6d - <std[664156f38db6df9a]::thread::lifecycle::spawn_unchecked<rustc_interface[952682f9f3d307b7]::util::run_in_thread_with_globals<rustc_interface[952682f9f3d307b7]::util::run_in_thread_pool_with_globals<rustc_interface[952682f9f3d307b7]::interface::run_compiler<(), rustc_driver_impl[2526e35b49e1b9f9]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[703624273cedab6d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:     0x7f1e2f99686c - <std[664156f38db6df9a]::sys::thread::unix::Thread>::new::thread_start
  30:     0x7f1e2966997a - <unknown>
  31:     0x7f1e296ed2bc - <unknown>
  32:                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.97.0-nightly (f53b654a8 2026-04-30) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir-dir=dir

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

Some errors have detailed explanations: E0282, E0601.
For more information about an error, try `rustc --explain E0282`.

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.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type
    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