Skip to content

[assumptions-on-binders] unwrap on None ICE in infer/context.rs during mir_borrowck with async closure capturing references #157678

@tmandry

Description

@tmandry

I tried this code:

use std::future::Future;

fn block_on<F: Future + Send>(_: F) -> F::Output {
    todo!()
}

pub struct AcceptorView<'a>(&'a mut ());

impl<'a> AcceptorView<'a> {
    pub fn accept<E>(self, _element: E) -> impl Future<Output = Self> + Send {
        async move { todo!() }
    }
}

pub async fn with_acceptor_view<T>(_f: impl AsyncFnOnce(AcceptorView<'_>) -> T) -> T {
    todo!()
}

fn test() {
    let n0 = 17;
    let fv = "taco";

    block_on(async move {
        let _ = with_acceptor_view(async |acceptor| {
            let _ = acceptor.accept(&n0).await;
            fv
        })
        .await;
    });
}

godbolt

This reproducer was minimized with the help of Gemini.

I expected to see this happen: compiles with -Zassumptions-on-binders

Instead, this happened:

thread 'rustc' (3) panicked at /rustc-dev/cb46fbb8c6ea799c6fba9188ed889275c35a8c28/compiler/rustc_infer/src/infer/context.rs:53:71:
called `Option::unwrap()` on a `None` value

Meta

rustc --version --verbose:

rustc 1.98.0-nightly (cb46fbb8c 2026-06-08) running on x86_64-unknown-linux-gnu
Backtrace

thread 'rustc' (3) panicked at /rustc-dev/cb46fbb8c6ea799c6fba9188ed889275c35a8c28/compiler/rustc_infer/src/infer/context.rs:53:71:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7493a169e709 - <<std[199fe1b8c015e6e2]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[7495f95995ae8d97]::fmt::Display>::fmt
   1:     0x7493a1e1ccc8 - core[7495f95995ae8d97]::fmt::write
   2:     0x7493a16b4796 - <std[199fe1b8c015e6e2]::sys::stdio::unix::Stderr as std[199fe1b8c015e6e2]::io::Write>::write_fmt
   3:     0x7493a1673e9e - std[199fe1b8c015e6e2]::panicking::default_hook::{closure#0}
   4:     0x7493a1691663 - std[199fe1b8c015e6e2]::panicking::default_hook
   5:     0x7493a0482471 - std[199fe1b8c015e6e2]::panicking::update_hook::<alloc[8f6510e158daad5c]::boxed::Box<rustc_driver_impl[20f10c9e4139f03d]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7493a1691942 - std[199fe1b8c015e6e2]::panicking::panic_with_hook
   7:     0x7493a1673f94 - std[199fe1b8c015e6e2]::panicking::panic_handler::{closure#0}
   8:     0x7493a1668489 - std[199fe1b8c015e6e2]::sys::backtrace::__rust_end_short_backtrace::<std[199fe1b8c015e6e2]::panicking::panic_handler::{closure#0}, !>
   9:     0x7493a16759cd - __rustc[395a943e405b99f2]::rust_begin_unwind
  10:     0x74939e1a83bc - core[7495f95995ae8d97]::panicking::panic_fmt
  11:     0x74939e84be62 - core[7495f95995ae8d97]::panicking::panic
  12:     0x74939e385619 - core[7495f95995ae8d97]::option::unwrap_failed
  13:     0x7493a08ecbc5 - <rustc_infer[42940245c1f29b]::infer::InferCtxt as rustc_type_ir[4a382f7e4de72543]::infer_ctxt::InferCtxtLike>::get_placeholder_assumptions
  14:     0x7493a130c5d2 - rustc_type_ir[4a382f7e4de72543]::region_constraint::eagerly_handle_placeholders_in_universe::<rustc_infer[42940245c1f29b]::infer::InferCtxt, rustc_middle[28fd0fe8ea2017f3]::ty::context::TyCtxt>
  15:     0x7493a27011c2 - <rustc_next_trait_solver[2dc99ed35efa9687]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[b4bd64afa4a6efe6]::solve::delegate::SolverDelegate, rustc_middle[28fd0fe8ea2017f3]::ty::context::TyCtxt>>::evaluate_added_goals_and_make_canonical_response::{closure#0}
  16:     0x7493a295fec9 - <rustc_next_trait_solver[2dc99ed35efa9687]::solve::search_graph::SearchGraphDelegate<rustc_trait_selection[b4bd64afa4a6efe6]::solve::delegate::SolverDelegate> as rustc_type_ir[4a382f7e4de72543]::search_graph::Delegate>::compute_goal::{closure#0}
  17:     0x74939e2c9e34 - <rustc_type_ir[4a382f7e4de72543]::search_graph::SearchGraph<rustc_next_trait_solver[2dc99ed35efa9687]::solve::search_graph::SearchGraphDelegate<rustc_trait_selection[b4bd64afa4a6efe6]::solve::delegate::SolverDelegate>, rustc_middle[28fd0fe8ea2017f3]::ty::context::TyCtxt>>::evaluate_goal::{closure#0}
  18:     0x7493a298121f - <rustc_next_trait_solver[2dc99ed35efa9687]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[b4bd64afa4a6efe6]::solve::delegate::SolverDelegate, rustc_middle[28fd0fe8ea2017f3]::ty::context::TyCtxt>>::evaluate_goal_raw
  19:     0x7493a297a828 - <rustc_trait_selection[b4bd64afa4a6efe6]::solve::fulfill::FulfillmentCtxt<rustc_infer[42940245c1f29b]::traits::engine::ScrubbedTraitError> as rustc_infer[42940245c1f29b]::traits::engine::TraitEngine<rustc_infer[42940245c1f29b]::traits::engine::ScrubbedTraitError>>::evaluate_obligations_error_on_ambiguity
  20:     0x7493a2993abe - <rustc_borrowck[4298966c654cdddb]::type_check::InstantiateOpaqueType as rustc_trait_selection[b4bd64afa4a6efe6]::traits::query::type_op::TypeOp>::fully_perform
  21:     0x7493a2993453 - <rustc_borrowck[4298966c654cdddb]::type_check::TypeChecker>::fully_perform_op::<(), rustc_borrowck[4298966c654cdddb]::type_check::InstantiateOpaqueType>
  22:     0x7493a299321a - <rustc_borrowck[4298966c654cdddb]::type_check::relate_tys::NllTypeRelating as rustc_type_ir[4a382f7e4de72543]::relate::combine::PredicateEmittingRelation<rustc_infer[42940245c1f29b]::infer::InferCtxt, rustc_middle[28fd0fe8ea2017f3]::ty::context::TyCtxt>>::register_predicates::<[rustc_type_ir[4a382f7e4de72543]::binder::Binder<rustc_middle[28fd0fe8ea2017f3]::ty::context::TyCtxt, rustc_type_ir[4a382f7e4de72543]::predicate_kind::PredicateKind<rustc_middle[28fd0fe8ea2017f3]::ty::context::TyCtxt>>; 1usize]>
  23:     0x7493a3b7ce1f - rustc_type_ir[4a382f7e4de72543]::relate::combine::super_combine_tys::<rustc_infer[42940245c1f29b]::infer::InferCtxt, rustc_middle[28fd0fe8ea2017f3]::ty::context::TyCtxt, rustc_borrowck[4298966c654cdddb]::type_check::relate_tys::NllTypeRelating>.cold
  24:     0x7493a337fe76 - <rustc_borrowck[4298966c654cdddb]::type_check::TypeChecker as rustc_middle[28fd0fe8ea2017f3]::mir::visit::Visitor>::visit_body
  25:     0x74939e9eea61 - rustc_borrowck[4298966c654cdddb]::type_check::type_check
  26:     0x7493a2f15e55 - <rustc_borrowck[4298966c654cdddb]::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
  27:     0x7493a2f10c9b - rustc_borrowck[4298966c654cdddb]::mir_borrowck
  28:     0x7493a2f10a59 - rustc_query_impl[24144f4510fbea2]::query_impl::mir_borrowck::invoke_provider_fn::__rust_begin_short_backtrace
  29:     0x7493a25b0266 - rustc_query_impl[24144f4510fbea2]::execution::try_execute_query::<rustc_data_structures[f1b5421a178956d7]::vec_cache::VecCache<rustc_span[472837f4c46cc99a]::def_id::LocalDefId, rustc_middle[28fd0fe8ea2017f3]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[28fd0fe8ea2017f3]::dep_graph::graph::DepNodeIndex>, false>
  30:     0x7493a25ad283 - rustc_query_impl[24144f4510fbea2]::query_impl::mir_borrowck::execute_query_non_incr::__rust_end_short_backtrace
  31:     0x7493a25ad454 - <rustc_middle[28fd0fe8ea2017f3]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[49d71893895d7a60]::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  32:     0x7493a25ac7d4 - rustc_interface[49d71893895d7a60]::passes::analysis
  33:     0x7493a2f8de46 - rustc_query_impl[24144f4510fbea2]::execution::try_execute_query::<rustc_middle[28fd0fe8ea2017f3]::query::caches::SingleCache<rustc_middle[28fd0fe8ea2017f3]::query::erase::ErasedData<[u8; 0usize]>>, false>
  34:     0x7493a2f8dc29 - rustc_query_impl[24144f4510fbea2]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  35:     0x7493a2f64428 - rustc_interface[49d71893895d7a60]::interface::run_compiler::<(), rustc_driver_impl[20f10c9e4139f03d]::run_compiler::{closure#0}>::{closure#1}
  36:     0x7493a2fa0fba - std[199fe1b8c015e6e2]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[49d71893895d7a60]::util::run_in_thread_with_globals<rustc_interface[49d71893895d7a60]::util::run_in_thread_pool_with_globals<rustc_interface[49d71893895d7a60]::interface::run_compiler<(), rustc_driver_impl[20f10c9e4139f03d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  37:     0x7493a2fa0d6d - <std[199fe1b8c015e6e2]::thread::lifecycle::spawn_unchecked<rustc_interface[49d71893895d7a60]::util::run_in_thread_with_globals<rustc_interface[49d71893895d7a60]::util::run_in_thread_pool_with_globals<rustc_interface[49d71893895d7a60]::interface::run_compiler<(), rustc_driver_impl[20f10c9e4139f03d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[7495f95995ae8d97]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x7493a2f97250 - <std[199fe1b8c015e6e2]::sys::thread::unix::Thread>::new::thread_start
  39:     0x74939c49caa4 - <unknown>
  40:     0x74939c529c6c - <unknown>
  41:                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 `/app/rustc-ice-2026-06-09T18_26_30-1.txt` to your bug report

note: rustc 1.98.0-nightly (cb46fbb8c 2026-06-08) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C llvm-args=--x86-asm-syntax=intel --crate-type rlib -Z next-solver -Z assumptions-on-binders

query stack during panic:
#0 [mir_borrowck] borrow-checking `test`
#1 [analysis] running analysis passes on crate `example`
end of query stack
Compiler returned: 101

Metadata

Metadata

Assignees

Labels

-Zassumptions-on-bindersUnstable option: `-Zassumptions-on-bindersA-closuresArea: Closures (`|…| { … }`)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

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