rust-lang / rust-lang/rust

ICE: `late-bound type parameter not allowed on function pointer types`

Open
#141,293 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

auto-reduced (treereduce-rust):

//@compile-flags: --crate-type=lib
#![feature(unsafe_binders)]

use std::unsafe_binder::wrap_binder;

//

fn propagate() -> unsafe<'a> i32 {
    unsafe {
        let x = 1;
        let binder: unsafe<featurea> i32 = wrap_binder!(x);
        binder
    }
}

original:

// skip-filecheck
//@ test-mir-pass: GVN

// EMIT_MIR gvn_on_unsafe_binder.test.GVN.diff
// EMIT_MIR gvn_on_unsafe_binder.propagate.GVN.diff

#![feature(unsafe_binders)]

use std::unsafe_binder::wrap_binder;

// Test for ICE <https://github.com/rust-lang/rust/issues/137846>.
fn test() {
    unsafe {
        let x = 1;
        let binder: unsafe<'a> &'a i32 = wrap_binder!(&x);
    }
}

// Test that GVN propagates const values through unsafe binders.
//
// The lifetime `'a` is redundant (and doesn't print when we print out the type).
// However, we need it so that rustfmt doesn't rip out the `unsafe<>` part for now.
fn propagate() -> unsafe<'a> i32 {
    unsafe {
        let x = 1;
        let binder: unsafe<featurea> i32 = wrap_binder!(x);
        binder
    }
}

Version information

rustc 1.89.0-nightly (28174fc1a 2025-05-20)
binary: rustc
commit-hash: 28174fc1a0525888615c8bce8f4ecec13c85ecc6
commit-date: 2025-05-20
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --crate-type=lib

Program output

warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.RvqJiZ8HHoz7/rustc_testrunner_tmpdir_reporting.UkivTDuCeQWZ/mvce.rs:1:12
  |
1 | #![feature(unsafe_binders)]
  |            ^^^^^^^^^^^^^^
  |
  = note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: type parameter `featurea` should have an upper camel case name
  --> /tmp/icemaker_global_tempdir.RvqJiZ8HHoz7/rustc_testrunner_tmpdir_reporting.UkivTDuCeQWZ/mvce.rs:10:28
   |
10 |         let binder: unsafe<featurea> i32 = wrap_binder!(x);
   |                            ^^^^^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Featurea`
   |
   = note: `#[warn(non_camel_case_types)]` on by default

warning: function `propagate` is never used
 --> /tmp/icemaker_global_tempdir.RvqJiZ8HHoz7/rustc_testrunner_tmpdir_reporting.UkivTDuCeQWZ/mvce.rs:7:4
  |
7 | fn propagate() -> unsafe<'a> i32 {
  |    ^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 3 warnings emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: late-bound type parameter not allowed on function pointer types
  --> /tmp/icemaker_global_tempdir.RvqJiZ8HHoz7/rustc_testrunner_tmpdir_reporting.UkivTDuCeQWZ/mvce.rs:10:28
   |
10 |         let binder: unsafe<featurea> i32 = wrap_binder!(x);
   |                            ^^^^^^^^
   |
note: delayed at compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:2504:30
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::diagnostic::Diag>::emit_unless
         4: rustc_hir_analysis::collect::resolve_bound_vars::deny_non_region_late_bound
         5: <rustc_hir_analysis::collect::resolve_bound_vars::BoundVarContext as rustc_hir::intravisit::Visitor>::visit_ty
         6: rustc_hir::intravisit::walk_block::<rustc_hir_analysis::collect::resolve_bound_vars::BoundVarContext>
         7: <rustc_hir_analysis::collect::resolve_bound_vars::BoundVarContext as rustc_hir::intravisit::Visitor>::visit_fn
         8: rustc_hir::intravisit::walk_item::<rustc_hir_analysis::collect::resolve_bound_vars::BoundVarContext>
         9: <rustc_hir_analysis::collect::resolve_bound_vars::BoundVarContext as rustc_hir::intravisit::Visitor>::visit_item
        10: rustc_hir_analysis::collect::resolve_bound_vars::resolve_bound_vars
        11: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::resolve_bound_vars::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        12: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        13: rustc_query_impl::query_impl::resolve_bound_vars::get_query_non_incr::__rust_end_short_backtrace
        14: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::late_bound_vars_map::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        16: rustc_query_impl::query_impl::late_bound_vars_map::get_query_non_incr::__rust_end_short_backtrace
        17: <rustc_middle::ty::context::TyCtxt>::late_bound_vars
        18: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_fn_ty
        19: rustc_hir_analysis::collect::lower_fn_sig_recovering_infer_ret_ty
        20: rustc_hir_analysis::collect::fn_sig
        21: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::fn_sig::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 24]>>
        22: <rustc_query_impl::query_impl::fn_sig::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId)>>::call_once
        23: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 24]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        24: rustc_query_impl::query_impl::fn_sig::get_query_non_incr::__rust_end_short_backtrace
        25: <rustc_hir_analysis::collect::CollectItemTypesVisitor as rustc_hir::intravisit::Visitor>::visit_item
        26: rustc_hir_analysis::check::wfcheck::check_well_formed
        27: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        28: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 1]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        29: rustc_query_impl::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
        30: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
        31: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        32: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        33: rustc_query_impl::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
        34: rustc_hir_analysis::check_crate
        35: rustc_interface::passes::run_required_analyses
        36: rustc_interface::passes::analysis
        37: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
        38: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        39: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        40: 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}
        41: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        42: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        43: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        44: std::sys::pal::unix::thread::Thread::new::thread_start
        45: <unknown>
        46: <unknown>
  --> /tmp/icemaker_global_tempdir.RvqJiZ8HHoz7/rustc_testrunner_tmpdir_reporting.UkivTDuCeQWZ/mvce.rs:10:28
   |
10 |         let binder: unsafe<featurea> i32 = wrap_binder!(x);
   |                            ^^^^^^^^

error: internal compiler error: unexpected generic param: GenericParam { hir_id: HirId(DefId(0:4 ~ mvce[4db4]::propagate).9), def_id: DefId(0:6 ~ mvce[4db4]::propagate::featurea), name: Plain(featurea#0), span: /tmp/icemaker_global_tempdir.RvqJiZ8HHoz7/rustc_testrunner_tmpdir_reporting.UkivTDuCeQWZ/mvce.rs:10:28: 10:36 (#0), pure_wrt_drop: false, kind: Type { default: None, synthetic: false }, colon_span: None, source: Binder }
  --> /tmp/icemaker_global_tempdir.RvqJiZ8HHoz7/rustc_testrunner_tmpdir_reporting.UkivTDuCeQWZ/mvce.rs:10:28
   |
10 |         let binder: unsafe<featurea> i32 = wrap_binder!(x);
   |                            ^^^^^^^^
   |
note: delayed at compiler/rustc_hir_typeck/src/writeback.rs:301:22
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         4: <rustc_hir_typeck::writeback::WritebackCx as rustc_hir::intravisit::Visitor>::visit_generic_param.cold
         5: <rustc_hir_typeck::writeback::WritebackCx as rustc_hir::intravisit::Visitor>::visit_ty
         6: <rustc_hir_typeck::writeback::WritebackCx as rustc_hir::intravisit::Visitor>::visit_local
         7: <rustc_hir_typeck::writeback::WritebackCx as rustc_hir::intravisit::Visitor>::visit_expr
         8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::resolve_type_vars_in_body
         9: rustc_hir_typeck::typeck_with_inspect::{closure#0}
        10: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        11: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        12: rustc_query_impl::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
        13: rustc_hir_analysis::check_crate
        14: rustc_interface::passes::run_required_analyses
        15: rustc_interface::passes::analysis
        16: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
        17: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        18: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        19: 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}
        20: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        21: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        22: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        23: std::sys::pal::unix::thread::Thread::new::thread_start
        24: <unknown>
        25: <unknown>
  --> /tmp/icemaker_global_tempdir.RvqJiZ8HHoz7/rustc_testrunner_tmpdir_reporting.UkivTDuCeQWZ/mvce.rs:10:28
   |
10 |         let binder: unsafe<featurea> i32 = wrap_binder!(x);
   |                            ^^^^^^^^

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.89.0-nightly (28174fc1a 2025-05-20) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -Z dump-mir-dir=dir

query stack during panic:
end of query stack

@rustbot label +F-unsafe_binders

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

Start with the reduced reproducer in a.rs and run rustc with --crate-type=lib and the unsafe_binders feature. Read rustc_hir_analysis/src/collect/resolve_bound_vars.rs around line 2504 and rustc_hir_typeck/src/writeback.rs around line 301, where the delayed ICEs are reported. Done means the reproducer no longer emits an internal compiler error.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.