Skip to content

[ICE]: delegation inside const generics: unreachable #155125

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(min_generic_const_args)]

impl
    S<
        {
            fn foo() {}
            reuse foo;
            2
        },
    >
{
}

original:

#![feature(min_generic_const_args, fn_delegation)]

pub struct S<const N: usize>;
impl
    S<
        {
            fn foo() {}
            reuse foo;
            2
        },
    >
{
}
fn main() {}

Version information

rustc 1.96.0-nightly (b6100ccf7 2026-04-10)
binary: rustc
commit-hash: b6100ccf71c092dd01e7a68930360892545ee4fb
commit-date: 2026-04-10
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.2

Possibly related line of code:

}
// For trait impl's `sig_id` is always equal to the corresponding trait method.
// For inherent methods delegation is not yet supported.
(FnKind::AssocTraitImpl, _)
| (_, FnKind::AssocTraitImpl)
| (_, FnKind::AssocInherentImpl) => unreachable!(),
}
}
fn get_parent_and_inheritance_kind<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: LocalDefId,

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

Program output

error[E0428]: the name `foo` is defined multiple times
 --> /tmp/icemaker_global_tempdir.z0ln3HisWVQe/rustc_testrunner_tmpdir_reporting.qim5eRo2o2Lc/mvce.rs:7:13
  |
6 |             fn foo() {}
  |             -------- previous definition of the value `foo` here
7 |             reuse foo;
  |             ^^^^^^^^^^ `foo` redefined here
  |
  = note: `foo` must be defined only once in the value namespace of this block

error[E0425]: cannot find type `S` in this scope
 --> /tmp/icemaker_global_tempdir.z0ln3HisWVQe/rustc_testrunner_tmpdir_reporting.qim5eRo2o2Lc/mvce.rs:4:5
  |
4 |     S<
  |     ^ not found in this scope

error[E0658]: functions delegation is not yet fully implemented
 --> /tmp/icemaker_global_tempdir.z0ln3HisWVQe/rustc_testrunner_tmpdir_reporting.qim5eRo2o2Lc/mvce.rs:7:13
  |
7 |             reuse foo;
  |             ^^^^^^^^^^
  |
  = 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-04-10; consider upgrading it if it is out of date

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

error: complex const arguments must be placed inside of a `const` block
 --> /tmp/icemaker_global_tempdir.z0ln3HisWVQe/rustc_testrunner_tmpdir_reporting.qim5eRo2o2Lc/mvce.rs:5:9
  |
5 | /         {
6 | |             fn foo() {}
7 | |             reuse foo;
8 | |             2
9 | |         },
  | |_________^

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.z0ln3HisWVQe/rustc_testrunner_tmpdir_reporting.qim5eRo2o2Lc/mvce.rs:12:2
   |
12 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.z0ln3HisWVQe/rustc_testrunner_tmpdir_reporting.qim5eRo2o2Lc/mvce.rs`


thread 'rustc' (237797) panicked at /rustc-dev/b6100ccf71c092dd01e7a68930360892545ee4fb/compiler/rustc_hir_analysis/src/delegation.rs:229:45:
internal error: entered unreachable code
stack backtrace:
   0:     0x7f462bc2184b - <<std[b6aa8882c14016da]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[e4da270f91b7d96]::fmt::Display>::fmt
   1:     0x7f462c21f108 - core[e4da270f91b7d96]::fmt::write
   2:     0x7f462bc38b16 - <std[b6aa8882c14016da]::sys::stdio::unix::Stderr as std[b6aa8882c14016da]::io::Write>::write_fmt
   3:     0x7f462bbf7b48 - std[b6aa8882c14016da]::panicking::default_hook::{closure#0}
   4:     0x7f462bc14eb3 - std[b6aa8882c14016da]::panicking::default_hook
   5:     0x7f462abf400c - std[b6aa8882c14016da]::panicking::update_hook::<alloc[30a42be7067dbe69]::boxed::Box<rustc_driver_impl[12e5e9e19b3364e8]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f462bc15192 - std[b6aa8882c14016da]::panicking::panic_with_hook
   7:     0x7f462bbf7c3a - std[b6aa8882c14016da]::panicking::panic_handler::{closure#0}
   8:     0x7f462bbee949 - std[b6aa8882c14016da]::sys::backtrace::__rust_end_short_backtrace::<std[b6aa8882c14016da]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f462bbf966d - __rustc[aa4d8a36e14f0fb8]::rust_begin_unwind
  10:     0x7f462874e49c - core[e4da270f91b7d96]::panicking::panic_fmt
  11:     0x7f46295370a2 - core[e4da270f91b7d96]::panicking::panic
  12:     0x7f462ad93520 - rustc_hir_analysis[a3ea64b35a81e47a]::delegation::get_delegation_parent_args_count_without_self
  13:     0x7f462ad8fc0a - rustc_hir_analysis[a3ea64b35a81e47a]::delegation::create_folder_and_args
  14:     0x7f462ad92b5a - rustc_hir_analysis[a3ea64b35a81e47a]::delegation::inherit_predicates_for_delegation_item
  15:     0x7f462c480279 - rustc_hir_analysis[a3ea64b35a81e47a]::collect::predicates_of::gather_explicit_predicates_of
  16:     0x7f462c479e5d - rustc_query_impl[fccebca9ed3ba15e]::query_impl::explicit_predicates_of::invoke_provider_fn::__rust_begin_short_backtrace
  17:     0x7f462c48e543 - rustc_query_impl[fccebca9ed3ba15e]::execution::try_execute_query::<rustc_middle[c5ddd56d26939a40]::query::caches::DefIdCache<rustc_middle[c5ddd56d26939a40]::query::erase::ErasedData<[u8; 24usize]>>, false>
  18:     0x7f462c48dce5 - rustc_query_impl[fccebca9ed3ba15e]::query_impl::explicit_predicates_of::execute_query_non_incr::__rust_end_short_backtrace
  19:     0x7f462c48d27f - rustc_query_impl[fccebca9ed3ba15e]::query_impl::predicates_of::invoke_provider_fn::__rust_begin_short_backtrace
  20:     0x7f462c48e52b - rustc_query_impl[fccebca9ed3ba15e]::execution::try_execute_query::<rustc_middle[c5ddd56d26939a40]::query::caches::DefIdCache<rustc_middle[c5ddd56d26939a40]::query::erase::ErasedData<[u8; 24usize]>>, false>
  21:     0x7f462c48dc13 - rustc_query_impl[fccebca9ed3ba15e]::query_impl::predicates_of::execute_query_non_incr::__rust_end_short_backtrace
  22:     0x7f462cd78ca7 - rustc_hir_analysis[a3ea64b35a81e47a]::check::check::check_item_type
  23:     0x7f462cd73d1c - rustc_hir_analysis[a3ea64b35a81e47a]::check::wfcheck::check_well_formed
  24:     0x7f462cd73cef - rustc_query_impl[fccebca9ed3ba15e]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  25:     0x7f462cd73324 - rustc_query_impl[fccebca9ed3ba15e]::execution::try_execute_query::<rustc_data_structures[eea759bf0ab68cb0]::vec_cache::VecCache<rustc_span[92bc7196f3184907]::def_id::LocalDefId, rustc_middle[c5ddd56d26939a40]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[c5ddd56d26939a40]::dep_graph::graph::DepNodeIndex>, false>
  26:     0x7f462cd730bb - rustc_query_impl[fccebca9ed3ba15e]::query_impl::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
  27:     0x7f462cd6f289 - rustc_hir_analysis[a3ea64b35a81e47a]::check::wfcheck::check_type_wf
  28:     0x7f462cd6f193 - rustc_query_impl[fccebca9ed3ba15e]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  29:     0x7f462d37fd1c - rustc_query_impl[fccebca9ed3ba15e]::execution::try_execute_query::<rustc_middle[c5ddd56d26939a40]::query::caches::SingleCache<rustc_middle[c5ddd56d26939a40]::query::erase::ErasedData<[u8; 1usize]>>, false>
  30:     0x7f462d37faf7 - rustc_query_impl[fccebca9ed3ba15e]::query_impl::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
  31:     0x7f462c5214a9 - rustc_hir_analysis[a3ea64b35a81e47a]::check_crate
  32:     0x7f462d142282 - rustc_interface[44cf4d623293f2c1]::passes::analysis
  33:     0x7f462d37d689 - rustc_query_impl[fccebca9ed3ba15e]::execution::try_execute_query::<rustc_middle[c5ddd56d26939a40]::query::caches::SingleCache<rustc_middle[c5ddd56d26939a40]::query::erase::ErasedData<[u8; 0usize]>>, false>
  34:     0x7f462d37d2e9 - rustc_query_impl[fccebca9ed3ba15e]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  35:     0x7f462d3aa0de - rustc_interface[44cf4d623293f2c1]::interface::run_compiler::<(), rustc_driver_impl[12e5e9e19b3364e8]::run_compiler::{closure#0}>::{closure#1}
  36:     0x7f462d35d4fe - std[b6aa8882c14016da]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[44cf4d623293f2c1]::util::run_in_thread_with_globals<rustc_interface[44cf4d623293f2c1]::util::run_in_thread_pool_with_globals<rustc_interface[44cf4d623293f2c1]::interface::run_compiler<(), rustc_driver_impl[12e5e9e19b3364e8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  37:     0x7f462d35dda0 - <std[b6aa8882c14016da]::thread::lifecycle::spawn_unchecked<rustc_interface[44cf4d623293f2c1]::util::run_in_thread_with_globals<rustc_interface[44cf4d623293f2c1]::util::run_in_thread_pool_with_globals<rustc_interface[44cf4d623293f2c1]::interface::run_compiler<(), rustc_driver_impl[12e5e9e19b3364e8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[e4da270f91b7d96]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x7f462d35ec2c - <std[b6aa8882c14016da]::sys::thread::unix::Thread>::new::thread_start
  39:     0x7f4626ea597a - <unknown>
  40:     0x7f4626f292bc - <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: rustc 1.96.0-nightly (b6100ccf7 2026-04-10) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [explicit_predicates_of] computing explicit predicates of `<impl at /tmp/icemaker_global_tempdir.z0ln3HisWVQe/rustc_testrunner_tmpdir_reporting.qim5eRo2o2Lc/mvce.rs:3:1: 10:6>::foo`
#1 [predicates_of] computing predicates of `<impl at /tmp/icemaker_global_tempdir.z0ln3HisWVQe/rustc_testrunner_tmpdir_reporting.qim5eRo2o2Lc/mvce.rs:3:1: 10:6>::foo`
#2 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.z0ln3HisWVQe/rustc_testrunner_tmpdir_reporting.qim5eRo2o2Lc/mvce.rs:3:1: 10:6>::foo` is well-formed
#3 [check_type_wf] checking that types are well-formed
#4 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 5 previous errors; 1 warning emitted

Some errors have detailed explanations: E0425, E0428, E0601, E0658.
For more information about an error, try `rustc --explain E0425`.

@rustbot label +F-min_generic_const_args +F-fn_delegation

Metadata

Metadata

Assignees

No one assigned

    Labels

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