rust-lang / rust-lang/rust

closure_lifetime_binder with explicit lifetime annotation gives ICE: "cannot convert ReLateParam […] to a region vid"

Open
#141,504 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-lifetimes C-bug F-closure_lifetime_binder I-ICE S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
#![feature(closure_lifetime_binder)]

fn fails() {
    callback(for<'a> |y: &'a mut i32| -> () {
        let _: &'a mut i32 = y;
    });
}

fn callback(_: impl for<'a> FnOnce(&'a mut i32)) {}

@rustbot labels +F-closure_lifetime_binder

This issue was discovered while experimenting with #141481

Meta

Reproducible on the playground with rustc 1.89.0-nightly (2025-05-23 3e674b06b5c74adea662)

Error output
Backtrace

error: internal compiler error: compiler/rustc_borrowck/src/universal_regions.rs:928:36: cannot convert `ReLateParam(DefId(0:4 ~ playground[7ed8]::fails::{closure#0}), LateNamed(DefId(0:5 ~ playground[7ed8]::fails::{closure#0}::'a), 'a))` to a region vid


thread 'rustc' panicked at compiler/rustc_borrowck/src/universal_regions.rs:928:36:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_borrowck::type_check::TypeChecker>::push_region_constraints
   7: <rustc_borrowck::type_check::TypeChecker>::ascribe_user_type
   8: rustc_borrowck::do_mir_borrowck
   9: <rustc_borrowck::root_cx::BorrowCheckRootCtxt>::get_or_insert_nested
  10: rustc_borrowck::mir_borrowck
      [... omitted 1 frame ...]
  11: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  12: rustc_interface::passes::run_required_analyses
  13: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  14: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  15: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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-05-24T13_36_39-26.txt` to your bug report

note: compiler flags: --crate-type lib -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 [mir_borrowck] borrow-checking `fails`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `playground` (lib)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the ICE with the supplied closure_lifetime_binder example on a current nightly, then inspect compiler/rustc_borrowck/src/universal_regions.rs around line 928 and the push_region_constraints and ascribe_user_type paths named in the backtrace. Determine the expected handling of the explicit late-bound lifetime, ensure the example no longer triggers an internal compiler error, and add regression coverage if the relevant test location is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.