Skip to content

[ICE]: delegation: No HirId for DefId #154332

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

fn a() {}

reuse a as b {
        let closure = || {
            fn foo<'a, 'b, T: Clone, const N: usize, U: Clone>(, ) {}

            reuse foo::<String, 1, String> as bar;
            
        };

        closure();
    } 

original:

#![feature(fn_delegation)]
#![allow(incomplete_features)]

fn a() {}

reuse a as b {
        let closure = || {
            fn foo<'a, 'b, T: Clone, const N: usize, U: Clone>(_t: &'a T, _u: &'b U) {}

            reuse foo::<String, 1, String> as bar;
            bar(&"".to_string(), &"".to_string());
        };

        closure();
    } //~ ERROR an inner attribute is not permitted in this context

fn main() {}

Version information

rustc 1.96.0-nightly (0312931d8 2026-03-24)
binary: rustc
commit-hash: 0312931d8c0ba1a28268a12c06202b68cbc65f76
commit-date: 2026-03-24
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.0

Possibly related line of code:

providers.hir_crate_items = map::hir_crate_items;
providers.crate_hash = map::crate_hash;
providers.hir_module_items = map::hir_module_items;
providers.local_def_id_to_hir_id = |tcx, def_id| match tcx.hir_crate(()).owner(tcx, def_id) {
MaybeOwner::Owner(_) => HirId::make_owner(def_id),
MaybeOwner::NonOwner(hir_id) => hir_id,
MaybeOwner::Phantom => bug!("No HirId for {:?}", def_id),
};
providers.opt_hir_owner_nodes =
|tcx, id| tcx.hir_crate(()).owner(tcx, id).as_owner().map(|i| &i.nodes);
providers.hir_owner_parent_q = |tcx, owner_id| tcx.hir_owner_parent_impl(owner_id);
providers.hir_attr_map = |tcx, id| {
tcx.hir_crate(()).owner(tcx, id.def_id).as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs)

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error: expected parameter name, found `,`
 --> /tmp/icemaker_global_tempdir.TJGRzDGRPjbZ/rustc_testrunner_tmpdir_reporting.fWMLkXu4AjP3/mvce.rs:8:64
  |
8 |             fn foo<'a, 'b, T: Clone, const N: usize, U: Clone>(, ) {}
  |                                                                ^ expected parameter name

error[E0658]: functions delegation is not yet fully implemented
  --> /tmp/icemaker_global_tempdir.TJGRzDGRPjbZ/rustc_testrunner_tmpdir_reporting.fWMLkXu4AjP3/mvce.rs:10:13
   |
10 |             reuse foo::<String, 1, String> as bar;
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #118212 <https://github.com/rust-lang/rust/issues/118212> for more information
   = help: add `#![feature(fn_delegation)]` to the crate attributes to enable
   = note: this compiler was built on 2026-03-24; consider upgrading it if it is out of date

error[E0658]: functions delegation is not yet fully implemented
  --> /tmp/icemaker_global_tempdir.TJGRzDGRPjbZ/rustc_testrunner_tmpdir_reporting.fWMLkXu4AjP3/mvce.rs:6:1
   |
 6 | / reuse a as b {
 7 | |         let closure = || {
 8 | |             fn foo<'a, 'b, T: Clone, const N: usize, U: Clone>(, ) {}
...  |
14 | |         closure();
15 | |     } 
   | |_____^
   |
   = note: see issue #118212 <https://github.com/rust-lang/rust/issues/118212> for more information
   = help: add `#![feature(fn_delegation)]` to the crate attributes to enable
   = note: this compiler was built on 2026-03-24; consider upgrading it if it is out of date

error: internal compiler error: /rustc-dev/0312931d8c0ba1a28268a12c06202b68cbc65f76/compiler/rustc_middle/src/hir/mod.rs:478:32: No HirId for DefId(0:5 ~ mvce[c8c2]::b::{closure#0})


thread 'rustc' (3048008) panicked at /rustc-dev/0312931d8c0ba1a28268a12c06202b68cbc65f76/compiler/rustc_middle/src/hir/mod.rs:478:32:
Box<dyn Any>
stack backtrace:
   0:     0x7f10db980ccb - <<std[7ac4a4f233f64e32]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[9fdad5ee2fa795]::fmt::Display>::fmt
   1:     0x7f10dc02f608 - core[9fdad5ee2fa795]::fmt::write
   2:     0x7f10db997cd6 - <std[7ac4a4f233f64e32]::sys::stdio::unix::Stderr as std[7ac4a4f233f64e32]::io::Write>::write_fmt
   3:     0x7f10db956cd8 - std[7ac4a4f233f64e32]::panicking::default_hook::{closure#0}
   4:     0x7f10db9740d3 - std[7ac4a4f233f64e32]::panicking::default_hook
   5:     0x7f10da97cfec - std[7ac4a4f233f64e32]::panicking::update_hook::<alloc[7be27c54429f639d]::boxed::Box<rustc_driver_impl[3e109776558d5f8]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f10db9743b2 - std[7ac4a4f233f64e32]::panicking::panic_with_hook
   7:     0x7f10da9acd01 - std[7ac4a4f233f64e32]::panicking::begin_panic::<rustc_errors[ad69bad4fcee133e]::ExplicitBug>::{closure#0}
   8:     0x7f10da9a5876 - std[7ac4a4f233f64e32]::sys::backtrace::__rust_end_short_backtrace::<std[7ac4a4f233f64e32]::panicking::begin_panic<rustc_errors[ad69bad4fcee133e]::ExplicitBug>::{closure#0}, !>
   9:     0x7f10da9a574b - std[7ac4a4f233f64e32]::panicking::begin_panic::<rustc_errors[ad69bad4fcee133e]::ExplicitBug>
  10:     0x7f10da9b8341 - <rustc_errors[ad69bad4fcee133e]::diagnostic::BugAbort as rustc_errors[ad69bad4fcee133e]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f10daf963c9 - rustc_middle[63ac57b1bbd193ad]::util::bug::opt_span_bug_fmt::<rustc_span[89e9e13b33feef16]::span_encoding::Span>::{closure#0}
  12:     0x7f10daf96552 - rustc_middle[63ac57b1bbd193ad]::ty::context::tls::with_opt::<rustc_middle[63ac57b1bbd193ad]::util::bug::opt_span_bug_fmt<rustc_span[89e9e13b33feef16]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7f10daf8701b - rustc_middle[63ac57b1bbd193ad]::ty::context::tls::with_context_opt::<rustc_middle[63ac57b1bbd193ad]::ty::context::tls::with_opt<rustc_middle[63ac57b1bbd193ad]::util::bug::opt_span_bug_fmt<rustc_span[89e9e13b33feef16]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7f10d875ef34 - rustc_middle[63ac57b1bbd193ad]::util::bug::bug_fmt
  15:     0x7f10dc12da13 - rustc_query_impl[1a62e37e1d040ce]::query_impl::local_def_id_to_hir_id::invoke_provider_fn::__rust_begin_short_backtrace
  16:     0x7f10dc12cd26 - rustc_query_impl[1a62e37e1d040ce]::execution::try_execute_query::<rustc_data_structures[7cb43e1d7eabe054]::vec_cache::VecCache<rustc_span[89e9e13b33feef16]::def_id::LocalDefId, rustc_middle[63ac57b1bbd193ad]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[63ac57b1bbd193ad]::dep_graph::graph::DepNodeIndex>, false>
  17:     0x7f10dc12ca85 - rustc_query_impl[1a62e37e1d040ce]::query_impl::local_def_id_to_hir_id::execute_query_non_incr::__rust_end_short_backtrace
  18:     0x7f10dc1899ff - <rustc_span[89e9e13b33feef16]::def_id::LocalDefId as rustc_hir[ec9fa394ae8173e]::attrs::HasAttrs<rustc_middle[63ac57b1bbd193ad]::ty::context::TyCtxt>>::get_attrs
  19:     0x7f10dc188ffb - rustc_query_impl[1a62e37e1d040ce]::query_impl::sanitizer_settings_for::invoke_provider_fn::__rust_begin_short_backtrace
  20:     0x7f10dc18843b - rustc_query_impl[1a62e37e1d040ce]::execution::try_execute_query::<rustc_data_structures[7cb43e1d7eabe054]::vec_cache::VecCache<rustc_span[89e9e13b33feef16]::def_id::LocalDefId, rustc_middle[63ac57b1bbd193ad]::query::erase::ErasedData<[u8; 4usize]>, rustc_middle[63ac57b1bbd193ad]::dep_graph::graph::DepNodeIndex>, false>
  21:     0x7f10dc1881bb - rustc_query_impl[1a62e37e1d040ce]::query_impl::sanitizer_settings_for::execute_query_non_incr::__rust_end_short_backtrace
  22:     0x7f10dc18906f - rustc_query_impl[1a62e37e1d040ce]::query_impl::sanitizer_settings_for::invoke_provider_fn::__rust_begin_short_backtrace
  23:     0x7f10dc18843b - rustc_query_impl[1a62e37e1d040ce]::execution::try_execute_query::<rustc_data_structures[7cb43e1d7eabe054]::vec_cache::VecCache<rustc_span[89e9e13b33feef16]::def_id::LocalDefId, rustc_middle[63ac57b1bbd193ad]::query::erase::ErasedData<[u8; 4usize]>, rustc_middle[63ac57b1bbd193ad]::dep_graph::graph::DepNodeIndex>, false>
  24:     0x7f10dc1881bb - rustc_query_impl[1a62e37e1d040ce]::query_impl::sanitizer_settings_for::execute_query_non_incr::__rust_end_short_backtrace
  25:     0x7f10dc17d731 - rustc_codegen_ssa[f4069af90124920b]::codegen_attrs::codegen_fn_attrs
  26:     0x7f10dc17be72 - rustc_query_impl[1a62e37e1d040ce]::query_impl::codegen_fn_attrs::invoke_provider_fn::__rust_begin_short_backtrace
  27:     0x7f10dc04fc4a - rustc_query_impl[1a62e37e1d040ce]::execution::try_execute_query::<rustc_middle[63ac57b1bbd193ad]::query::caches::DefIdCache<rustc_middle[63ac57b1bbd193ad]::query::erase::ErasedData<[u8; 8usize]>>, false>
  28:     0x7f10dc04f4d0 - rustc_query_impl[1a62e37e1d040ce]::query_impl::codegen_fn_attrs::execute_query_non_incr::__rust_end_short_backtrace
  29:     0x7f10da421bbc - <rustc_ast_lowering[76ab009d4d83260]::LoweringContext<rustc_ast_lowering[76ab009d4d83260]::ResolverDelayedAstLowering>>::lower_delegation
  30:     0x7f10da43b162 - <rustc_ast_lowering[76ab009d4d83260]::LoweringContext<rustc_ast_lowering[76ab009d4d83260]::ResolverDelayedAstLowering>>::lower_item_kind
  31:     0x7f10da46a669 - <rustc_ast_lowering[76ab009d4d83260]::item::ItemLowerer<rustc_ast_lowering[76ab009d4d83260]::ResolverDelayedAstLowering>>::lower_node
  32:     0x7f10da41d57b - rustc_ast_lowering[76ab009d4d83260]::lower_delayed_owner
  33:     0x7f10dc12bc27 - rustc_query_impl[1a62e37e1d040ce]::execution::try_execute_query::<rustc_data_structures[7cb43e1d7eabe054]::vec_cache::VecCache<rustc_span[89e9e13b33feef16]::def_id::LocalDefId, rustc_middle[63ac57b1bbd193ad]::query::erase::ErasedData<[u8; 0usize]>, rustc_middle[63ac57b1bbd193ad]::dep_graph::graph::DepNodeIndex>, false>
  34:     0x7f10db424dab - rustc_query_impl[1a62e37e1d040ce]::query_impl::lower_delayed_owner::execute_query_non_incr::__rust_end_short_backtrace
  35:     0x7f10dd3674a5 - rustc_middle[63ac57b1bbd193ad]::hir::map::hir_crate_items
  36:     0x7f10dd1fdd35 - rustc_query_impl[1a62e37e1d040ce]::query_impl::hir_crate_items::invoke_provider_fn::__rust_begin_short_backtrace
  37:     0x7f10dd1f8f20 - rustc_query_impl[1a62e37e1d040ce]::execution::try_execute_query::<rustc_middle[63ac57b1bbd193ad]::query::caches::SingleCache<rustc_middle[63ac57b1bbd193ad]::query::erase::ErasedData<[u8; 8usize]>>, false>
  38:     0x7f10dd1fa257 - rustc_query_impl[1a62e37e1d040ce]::query_impl::hir_crate_items::execute_query_non_incr::__rust_end_short_backtrace
  39:     0x7f10dc129418 - rustc_interface[96c6593d249ce29a]::passes::analysis
  40:     0x7f10dd1f9b49 - rustc_query_impl[1a62e37e1d040ce]::execution::try_execute_query::<rustc_middle[63ac57b1bbd193ad]::query::caches::SingleCache<rustc_middle[63ac57b1bbd193ad]::query::erase::ErasedData<[u8; 0usize]>>, false>
  41:     0x7f10dd1f98a9 - rustc_query_impl[1a62e37e1d040ce]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  42:     0x7f10dd21fad4 - rustc_interface[96c6593d249ce29a]::interface::run_compiler::<(), rustc_driver_impl[3e109776558d5f8]::run_compiler::{closure#0}>::{closure#1}
  43:     0x7f10dd1e60fe - std[7ac4a4f233f64e32]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[96c6593d249ce29a]::util::run_in_thread_with_globals<rustc_interface[96c6593d249ce29a]::util::run_in_thread_pool_with_globals<rustc_interface[96c6593d249ce29a]::interface::run_compiler<(), rustc_driver_impl[3e109776558d5f8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  44:     0x7f10dd1e69a0 - <std[7ac4a4f233f64e32]::thread::lifecycle::spawn_unchecked<rustc_interface[96c6593d249ce29a]::util::run_in_thread_with_globals<rustc_interface[96c6593d249ce29a]::util::run_in_thread_pool_with_globals<rustc_interface[96c6593d249ce29a]::interface::run_compiler<(), rustc_driver_impl[3e109776558d5f8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[9fdad5ee2fa795]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:     0x7f10dd1e782c - <std[7ac4a4f233f64e32]::sys::thread::unix::Thread>::new::thread_start
  46:     0x7f10d6ca597a - <unknown>
  47:     0x7f10d6d292bc - <unknown>
  48:                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: rustc 1.96.0-nightly (0312931d8 2026-03-24) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [local_def_id_to_hir_id] getting HIR ID of `b::{closure#0}`
#1 [sanitizer_settings_for] checking what set of sanitizers are enabled on `b::{closure#0}`
#2 [sanitizer_settings_for] checking what set of sanitizers are enabled on `b::{closure#0}::foo`
#3 [codegen_fn_attrs] computing codegen attributes of `b::{closure#0}::foo`
#4 [lower_delayed_owner] lowering the delayed AST owner `b::{closure#0}::bar`
#5 [hir_crate_items] getting HIR crate items
#6 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0658`.

@rustbot label +F-fn_delegation

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    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