Skip to content

ICE: Converting the closure to a function pointer triggers ICE. #146837

@bushilushan

Description

@bushilushan

This is a variant based on #125873 (which has already been fixed). I tried to convert the closure to a function pointer, and it triggered ICE again.

Code

#![feature(closure_lifetime_binder)]
fn foo() {
    let _: for<'a> fn(&'a ()) -> &'a () = for<'a> |b: &'a ()| -> &'a () {
        const {
            let awd = ();
            let _: &'a () = &awd;
            //~^ ERROR `awd` does not live long enough
        };
        b
    };
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.92.0-nightly (dd7fda570 2025-09-20)
binary: rustc
commit-hash: dd7fda570040e8a736f7d8bc28ddd1b444aabc82
commit-date: 2025-09-20
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.1

Error output

error: internal compiler error: compiler/rustc_borrowck/src/universal_regions.rs:930:36: cannot convert `ReLateParam(DefId(0:5 ~ example[6f6c]::foo::{closure#0}), LateNamed(DefId(0:6 ~ example[6f6c]::foo::{closure#0}::'a)))` to a region vid


thread 'rustc' (3) panicked at compiler/rustc_borrowck/src/universal_regions.rs:930:36:
Box<dyn Any>
Backtrace

stack backtrace:
   0:     0x741568205953 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1d9a860939142303
   1:     0x741568a01fc4 - core::fmt::write::h4cde2f6e6eca889f
   2:     0x7415681ba5f1 - std::io::Write::write_fmt::hbbb02a45894db6e0
   3:     0x7415681cb5d2 - std::sys::backtrace::BacktraceLock::print::hfcdaff63564fa703
   4:     0x7415681d1539 - std::panicking::default_hook::{{closure}}::hcc588fdbd9e0eddf
   5:     0x7415681d1063 - std::panicking::default_hook::h21841b6cba7fa436
   6:     0x7415671f5bd7 - std[6c96415bc1a38016]::panicking::update_hook::<alloc[c6e2df4d00e1f0b6]::boxed::Box<rustc_driver_impl[459800387efcc559]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7415681d195f - std::panicking::panic_with_hook::hedf05123aa8b61bb
   8:     0x741567232471 - std[6c96415bc1a38016]::panicking::begin_panic::<rustc_errors[af568b6d67acca2f]::ExplicitBug>::{closure#0}
   9:     0x741567225c86 - std[6c96415bc1a38016]::sys::backtrace::__rust_end_short_backtrace::<std[6c96415bc1a38016]::panicking::begin_panic<rustc_errors[af568b6d67acca2f]::ExplicitBug>::{closure#0}, !>
  10:     0x741567223729 - std[6c96415bc1a38016]::panicking::begin_panic::<rustc_errors[af568b6d67acca2f]::ExplicitBug>
  11:     0x74156723db61 - <rustc_errors[af568b6d67acca2f]::diagnostic::BugAbort as rustc_errors[af568b6d67acca2f]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7415677cfdba - rustc_middle[e11099e36afb5411]::util::bug::opt_span_bug_fmt::<rustc_span[9408016a182fdcc0]::span_encoding::Span>::{closure#0}
  13:     0x7415677cff7a - rustc_middle[e11099e36afb5411]::ty::context::tls::with_opt::<rustc_middle[e11099e36afb5411]::util::bug::opt_span_bug_fmt<rustc_span[9408016a182fdcc0]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7415677beb4b - rustc_middle[e11099e36afb5411]::ty::context::tls::with_context_opt::<rustc_middle[e11099e36afb5411]::ty::context::tls::with_opt<rustc_middle[e11099e36afb5411]::util::bug::opt_span_bug_fmt<rustc_span[9408016a182fdcc0]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7415658b9200 - rustc_middle[e11099e36afb5411]::util::bug::bug_fmt
  16:     0x7415692fcef6 - <rustc_borrowck[dd44c889f7481f64]::type_check::constraint_conversion::ConstraintConversion>::convert_all
  17:     0x74156936e0e6 - <rustc_borrowck[dd44c889f7481f64]::type_check::TypeChecker>::ascribe_user_type
  18:     0x741569366df9 - rustc_borrowck[dd44c889f7481f64]::type_check::type_check
  19:     0x741569bb5e40 - <rustc_borrowck[dd44c889f7481f64]::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
  20:     0x741569bae417 - rustc_borrowck[dd44c889f7481f64]::mir_borrowck
  21:     0x741569bae1dd - rustc_query_impl[8ceca73aa722394f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[8ceca73aa722394f]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e11099e36afb5411]::query::erase::Erased<[u8; 8usize]>>
  22:     0x741568be74c4 - rustc_query_system[44f2cb83942a7389]::query::plumbing::try_execute_query::<rustc_query_impl[8ceca73aa722394f]::DynamicConfig<rustc_data_structures[e568e5fb65a8620a]::vec_cache::VecCache<rustc_span[9408016a182fdcc0]::def_id::LocalDefId, rustc_middle[e11099e36afb5411]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[44f2cb83942a7389]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[8ceca73aa722394f]::plumbing::QueryCtxt, false>
  23:     0x741568bebe09 - rustc_query_impl[8ceca73aa722394f]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  24:     0x741568bebfbc - <rustc_middle[e11099e36afb5411]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[f4ad0248271d71d8]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  25:     0x741568be93cc - rustc_interface[f4ad0248271d71d8]::passes::analysis
  26:     0x741568be886d - rustc_query_impl[8ceca73aa722394f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[8ceca73aa722394f]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e11099e36afb5411]::query::erase::Erased<[u8; 0usize]>>
  27:     0x741569a65526 - rustc_query_system[44f2cb83942a7389]::query::plumbing::try_execute_query::<rustc_query_impl[8ceca73aa722394f]::DynamicConfig<rustc_query_system[44f2cb83942a7389]::query::caches::SingleCache<rustc_middle[e11099e36afb5411]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[8ceca73aa722394f]::plumbing::QueryCtxt, false>
  28:     0x741569a6517c - rustc_query_impl[8ceca73aa722394f]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  29:     0x741569c72d4f - rustc_interface[f4ad0248271d71d8]::passes::create_and_enter_global_ctxt::<core[88dcab6addd45e6c]::option::Option<rustc_interface[f4ad0248271d71d8]::queries::Linker>, rustc_driver_impl[459800387efcc559]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  30:     0x741569be96be - rustc_interface[f4ad0248271d71d8]::interface::run_compiler::<(), rustc_driver_impl[459800387efcc559]::run_compiler::{closure#0}>::{closure#1}
  31:     0x741569b482f8 - std[6c96415bc1a38016]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[f4ad0248271d71d8]::util::run_in_thread_with_globals<rustc_interface[f4ad0248271d71d8]::util::run_in_thread_pool_with_globals<rustc_interface[f4ad0248271d71d8]::interface::run_compiler<(), rustc_driver_impl[459800387efcc559]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  32:     0x741569b47fdc - <<std[6c96415bc1a38016]::thread::Builder>::spawn_unchecked_<rustc_interface[f4ad0248271d71d8]::util::run_in_thread_with_globals<rustc_interface[f4ad0248271d71d8]::util::run_in_thread_pool_with_globals<rustc_interface[f4ad0248271d71d8]::interface::run_compiler<(), rustc_driver_impl[459800387efcc559]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[88dcab6addd45e6c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x741569b4e68d - std::sys::thread::unix::Thread::new::thread_start::hb28ad79a6a69b48c
  34:     0x741563294ac3 - <unknown>
  35:     0x741563326850 - <unknown>
  36:                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: please attach the file at `/app/rustc-ice-2025-09-21T07_59_53-1.txt` to your bug report

note: compiler flags: -C debuginfo=2 --crate-type bin -C linker=/opt/compiler-explorer/gcc-15.2.0/bin/gcc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-closure_lifetime_binder`#![feature(closure_lifetime_binder)]`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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions