Skip to content

[ICE]: generics_of: unexpected node kind Crate(Mod #151708

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(min_generic_const_args)]
const N: usize = 2;

trait CollectArray<A> {
    fn inner_array(&mut self) -> [A; N];
}

fn main() {}

original:

//@ run-pass
//@ compile-flags:-Zmir-opt-level=3

use std::mem::MaybeUninit;
const N: usize = 2;

trait CollectArray<A>: Iterator<Item = A> {
    fn inner_array(&mut self) -> [A; N];
    fn collect_array(&mut self) -> [A; N] {
        let result = self.inner_array();
        assert!(self.next().is_none());
        result
    }
}

impl<A, I: Sized> CollectArray<A> for I
where
    I: Iterator<Item = A>,
{
    fn inner_array(&mut self) -> [A; N] {
        let mut result: [MaybeUninit<A>; N] = unsafe { MaybeUninit::uninit().assume_init() };
        for (dest, item) in result.iter_mut().zip(self) {
            *dest = MaybeUninit::new(item);
        }
        let temp_ptr: *const [MaybeUninit<A>; N] = &result;
        unsafe { std::ptr::read(temp_ptr as *const [A; N]) }
    }
}

fn main() {
    assert_eq!(
        [[1, 2], [3, 4]]
            .iter()
            .map(|row| row.iter().collect_array())
            .collect_array(),
        [[&1, &2], [&3, &4]]
    );
}

Version information

rustc 1.95.0-nightly (474276961 2026-01-26)
binary: rustc
commit-hash: 474276961f48b0d05f4ea260ba400096b027584e
commit-date: 2026-01-26
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 21.1.8

Possibly related line of code:

Node::Synthetic => span_bug!(
tcx.def_span(def_id),
"synthetic HIR should have its `generics_of` explicitly fed"
),
_ => span_bug!(tcx.def_span(def_id), "generics_of: unexpected node kind {node:?}"),
};
// Add in the self type parameter.
let opt_self = if let Node::Item(item) = node
&& let ItemKind::Trait(..) | ItemKind::TraitAlias(..) = item.kind
{

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(min_generic_const_args)

Program output

warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
 --> <crate attribute>: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

warning: constant `N` is never used
 --> /tmp/icemaker_global_tempdir.gU4NCxAeVxD3/rustc_testrunner_tmpdir_reporting.uVKmc2tJ06T0/mvce.rs:1:7
  |
1 | const N: usize = 2;
  |       ^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: trait `CollectArray` is never used
 --> /tmp/icemaker_global_tempdir.gU4NCxAeVxD3/rustc_testrunner_tmpdir_reporting.uVKmc2tJ06T0/mvce.rs:3:7
  |
3 | trait CollectArray<A> {
  |       ^^^^^^^^^^^^

error: internal compiler error: /rustc-dev/474276961f48b0d05f4ea260ba400096b027584e/compiler/rustc_hir_analysis/src/collect/generics_of.rs:212:14: generics_of: unexpected node kind Crate(Mod { spans: ModSpans { inner_span: /tmp/icemaker_global_tempdir.gU4NCxAeVxD3/rustc_testrunner_tmpdir_reporting.uVKmc2tJ06T0/mvce.rs:1:1: 7:13 (#0), inject_use_span: no-location (#0) }, item_ids: [ItemId { owner_id: DefId(0:1 ~ mvce[a1f3]::std) }, ItemId { owner_id: DefId(0:2 ~ mvce[a1f3]::{use#0}) }, ItemId { owner_id: DefId(0:3 ~ mvce[a1f3]::N) }, ItemId { owner_id: DefId(0:4 ~ mvce[a1f3]::CollectArray) }, ItemId { owner_id: DefId(0:7 ~ mvce[a1f3]::main) }] })
 --> /tmp/icemaker_global_tempdir.gU4NCxAeVxD3/rustc_testrunner_tmpdir_reporting.uVKmc2tJ06T0/mvce.rs:1:1
  |
1 | / const N: usize = 2;
2 | |
3 | | trait CollectArray<A> {
4 | |     fn inner_array(&mut self) -> [A; N];
... |
7 | | fn main() {}
  | |____________^


thread 'rustc' (4043844) panicked at /rustc-dev/474276961f48b0d05f4ea260ba400096b027584e/compiler/rustc_hir_analysis/src/collect/generics_of.rs:212:14:
Box<dyn Any>
stack backtrace:
   0:     0x7fd43ac39a03 - <<std[8cc15e19e2a5acfa]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[ea2bd7cd219b3eb9]::fmt::Display>::fmt
   1:     0x7fd43b20e61c - core[ea2bd7cd219b3eb9]::fmt::write
   2:     0x7fd43ac501a6 - <std[8cc15e19e2a5acfa]::sys::stdio::unix::Stderr as std[8cc15e19e2a5acfa]::io::Write>::write_fmt
   3:     0x7fd43ac0f898 - std[8cc15e19e2a5acfa]::panicking::default_hook::{closure#0}
   4:     0x7fd43ac2d033 - std[8cc15e19e2a5acfa]::panicking::default_hook
   5:     0x7fd439c18d2d - std[8cc15e19e2a5acfa]::panicking::update_hook::<alloc[d48b8b032ee4278d]::boxed::Box<rustc_driver_impl[b96920060a9f9ce8]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fd43ac2d312 - std[8cc15e19e2a5acfa]::panicking::panic_with_hook
   7:     0x7fd439c4d2c1 - std[8cc15e19e2a5acfa]::panicking::begin_panic::<rustc_errors[229f37ed4a6a6271]::ExplicitBug>::{closure#0}
   8:     0x7fd439c45ea6 - std[8cc15e19e2a5acfa]::sys::backtrace::__rust_end_short_backtrace::<std[8cc15e19e2a5acfa]::panicking::begin_panic<rustc_errors[229f37ed4a6a6271]::ExplicitBug>::{closure#0}, !>
   9:     0x7fd439c43aa9 - std[8cc15e19e2a5acfa]::panicking::begin_panic::<rustc_errors[229f37ed4a6a6271]::ExplicitBug>
  10:     0x7fd439c58421 - <rustc_errors[229f37ed4a6a6271]::diagnostic::BugAbort as rustc_errors[229f37ed4a6a6271]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7fd43a1dd3fc - <rustc_errors[229f37ed4a6a6271]::DiagCtxtHandle>::span_bug::<rustc_span[94ae33b9311191df]::span_encoding::Span, alloc[d48b8b032ee4278d]::string::String>
  12:     0x7fd43a205cb6 - rustc_middle[8d85aae3cf006bd8]::util::bug::opt_span_bug_fmt::<rustc_span[94ae33b9311191df]::span_encoding::Span>::{closure#0}
  13:     0x7fd43a205e62 - rustc_middle[8d85aae3cf006bd8]::ty::context::tls::with_opt::<rustc_middle[8d85aae3cf006bd8]::util::bug::opt_span_bug_fmt<rustc_span[94ae33b9311191df]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7fd43a1f6f5b - rustc_middle[8d85aae3cf006bd8]::ty::context::tls::with_context_opt::<rustc_middle[8d85aae3cf006bd8]::ty::context::tls::with_opt<rustc_middle[8d85aae3cf006bd8]::util::bug::opt_span_bug_fmt<rustc_span[94ae33b9311191df]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7fd437b0d2a8 - rustc_middle[8d85aae3cf006bd8]::util::bug::span_bug_fmt::<rustc_span[94ae33b9311191df]::span_encoding::Span>
  16:     0x7fd43bad6141 - rustc_hir_analysis[a3c3123a8725cc24]::collect::generics_of::generics_of
  17:     0x7fd43b211269 - rustc_query_impl[f52eeba12e8a164a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f52eeba12e8a164a]::query_impl::generics_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d85aae3cf006bd8]::query::erase::Erased<[u8; 8usize]>>
  18:     0x7fd43b211945 - rustc_query_system[54a10b0b4f070675]::query::plumbing::try_execute_query::<rustc_query_impl[f52eeba12e8a164a]::DynamicConfig<rustc_query_system[54a10b0b4f070675]::query::caches::DefIdCache<rustc_middle[8d85aae3cf006bd8]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[f52eeba12e8a164a]::plumbing::QueryCtxt, false>
  19:     0x7fd43b21166b - rustc_query_impl[f52eeba12e8a164a]::query_impl::generics_of::get_query_non_incr::__rust_end_short_backtrace
  20:     0x7fd43c3da63c - <rustc_middle[8d85aae3cf006bd8]::ty::context::TyCtxt as rustc_type_ir[f9818e68c953de5]::interner::Interner>::generics_of
  21:     0x7fd43aa25d9a - <rustc_type_ir[f9818e68c953de5]::predicate::TraitRef<rustc_middle[8d85aae3cf006bd8]::ty::context::TyCtxt>>::from_assoc
  22:     0x7fd43d11944d - <rustc_trait_selection[326fa56f4f3ccdfa]::traits::dyn_compatibility::IllegalSelfTypeVisitor as rustc_type_ir[f9818e68c953de5]::visit::TypeVisitor<rustc_middle[8d85aae3cf006bd8]::ty::context::TyCtxt>>::visit_const.cold
  23:     0x7fd43c21484d - rustc_trait_selection[326fa56f4f3ccdfa]::traits::dyn_compatibility::contains_illegal_self_type_reference::<rustc_type_ir[f9818e68c953de5]::binder::Binder<rustc_middle[8d85aae3cf006bd8]::ty::context::TyCtxt, rustc_middle[8d85aae3cf006bd8]::ty::Ty>>
  24:     0x7fd43c214b08 - rustc_trait_selection[326fa56f4f3ccdfa]::traits::dyn_compatibility::virtual_call_violations_for_method
  25:     0x7fd43c21b130 - rustc_trait_selection[326fa56f4f3ccdfa]::traits::dyn_compatibility::dyn_compatibility_violations_for_assoc_item
  26:     0x7fd43c21adda - <core[ea2bd7cd219b3eb9]::iter::adapters::flatten::FlatMap<core[ea2bd7cd219b3eb9]::iter::adapters::map::Map<core[ea2bd7cd219b3eb9]::iter::adapters::map::Map<core[ea2bd7cd219b3eb9]::slice::iter::Iter<(core[ea2bd7cd219b3eb9]::option::Option<rustc_span[94ae33b9311191df]::symbol::Symbol>, rustc_middle[8d85aae3cf006bd8]::ty::assoc::AssocItem)>, <rustc_data_structures[80b3ed06db703e49]::sorted_map::index_map::SortedIndexMultiMap<u32, core[ea2bd7cd219b3eb9]::option::Option<rustc_span[94ae33b9311191df]::symbol::Symbol>, rustc_middle[8d85aae3cf006bd8]::ty::assoc::AssocItem>>::iter::{closure#0}>, <rustc_middle[8d85aae3cf006bd8]::ty::assoc::AssocItems>::in_definition_order::{closure#0}>, alloc[d48b8b032ee4278d]::vec::Vec<rustc_middle[8d85aae3cf006bd8]::traits::DynCompatibilityViolation>, rustc_trait_selection[326fa56f4f3ccdfa]::traits::dyn_compatibility::dyn_compatibility_violations_for_trait::{closure#0}::{closure#0}> as core[ea2bd7cd219b3eb9]::iter::traits::iterator::Iterator>::next
  27:     0x7fd43c218d06 - <core[ea2bd7cd219b3eb9]::iter::adapters::GenericShunt<core[ea2bd7cd219b3eb9]::iter::adapters::map::Map<core[ea2bd7cd219b3eb9]::iter::adapters::flatten::FlatMap<core[ea2bd7cd219b3eb9]::iter::sources::from_fn::FromFn<rustc_type_ir[f9818e68c953de5]::elaborate::supertrait_def_ids<rustc_middle[8d85aae3cf006bd8]::ty::context::TyCtxt>::{closure#0}>, alloc[d48b8b032ee4278d]::vec::Vec<rustc_middle[8d85aae3cf006bd8]::traits::DynCompatibilityViolation>, rustc_trait_selection[326fa56f4f3ccdfa]::traits::dyn_compatibility::dyn_compatibility_violations::{closure#0}>, core[ea2bd7cd219b3eb9]::result::Result<rustc_middle[8d85aae3cf006bd8]::traits::DynCompatibilityViolation, !>::Ok>, core[ea2bd7cd219b3eb9]::result::Result<core[ea2bd7cd219b3eb9]::convert::Infallible, !>> as core[ea2bd7cd219b3eb9]::iter::traits::iterator::Iterator>::next
  28:     0x7fd43c21805b - rustc_trait_selection[326fa56f4f3ccdfa]::traits::dyn_compatibility::dyn_compatibility_violations
  29:     0x7fd43c217f54 - rustc_query_impl[f52eeba12e8a164a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f52eeba12e8a164a]::query_impl::dyn_compatibility_violations::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d85aae3cf006bd8]::query::erase::Erased<[u8; 16usize]>>
  30:     0x7fd43c217f21 - <rustc_query_impl[f52eeba12e8a164a]::query_impl::dyn_compatibility_violations::dynamic_query::{closure#2} as core[ea2bd7cd219b3eb9]::ops::function::FnOnce<(rustc_middle[8d85aae3cf006bd8]::ty::context::TyCtxt, rustc_span[94ae33b9311191df]::def_id::DefId)>>::call_once
  31:     0x7fd43b3265db - rustc_query_system[54a10b0b4f070675]::query::plumbing::try_execute_query::<rustc_query_impl[f52eeba12e8a164a]::DynamicConfig<rustc_query_system[54a10b0b4f070675]::query::caches::DefIdCache<rustc_middle[8d85aae3cf006bd8]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[f52eeba12e8a164a]::plumbing::QueryCtxt, false>
  32:     0x7fd43c09da9e - rustc_query_impl[f52eeba12e8a164a]::query_impl::dyn_compatibility_violations::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7fd43c09db4e - rustc_trait_selection[326fa56f4f3ccdfa]::traits::dyn_compatibility::is_dyn_compatible
  34:     0x7fd43c09dad3 - rustc_query_impl[f52eeba12e8a164a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f52eeba12e8a164a]::query_impl::is_dyn_compatible::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d85aae3cf006bd8]::query::erase::Erased<[u8; 1usize]>>
  35:     0x7fd43b7c4817 - rustc_query_system[54a10b0b4f070675]::query::plumbing::try_execute_query::<rustc_query_impl[f52eeba12e8a164a]::DynamicConfig<rustc_query_system[54a10b0b4f070675]::query::caches::DefIdCache<rustc_middle[8d85aae3cf006bd8]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[f52eeba12e8a164a]::plumbing::QueryCtxt, false>
  36:     0x7fd43b6e2250 - rustc_query_impl[f52eeba12e8a164a]::query_impl::is_dyn_compatible::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7fd43bbc0a8b - <rustc_lint[c1072c7a935321f8]::BuiltinCombinedModuleLateLintPass as rustc_lint[c1072c7a935321f8]::passes::LateLintPass>::check_item
  38:     0x7fd43bbb4df2 - <rustc_lint[c1072c7a935321f8]::late::LateContextAndPass<rustc_lint[c1072c7a935321f8]::BuiltinCombinedModuleLateLintPass> as rustc_hir[f8bf578c86c342b0]::intravisit::Visitor>::visit_nested_item
  39:     0x7fd43bbb36ed - rustc_lint[c1072c7a935321f8]::lint_mod
  40:     0x7fd43bbb3297 - rustc_query_impl[f52eeba12e8a164a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f52eeba12e8a164a]::query_impl::lint_mod::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d85aae3cf006bd8]::query::erase::Erased<[u8; 0usize]>>
  41:     0x7fd43bff836b - rustc_query_system[54a10b0b4f070675]::query::plumbing::try_execute_query::<rustc_query_impl[f52eeba12e8a164a]::DynamicConfig<rustc_query_system[54a10b0b4f070675]::query::caches::DefaultCache<rustc_span[94ae33b9311191df]::def_id::LocalModDefId, rustc_middle[8d85aae3cf006bd8]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[f52eeba12e8a164a]::plumbing::QueryCtxt, false>
  42:     0x7fd43bff97d5 - rustc_query_impl[f52eeba12e8a164a]::query_impl::lint_mod::get_query_non_incr::__rust_end_short_backtrace
  43:     0x7fd43bff9390 - rustc_lint[c1072c7a935321f8]::late::check_crate::{closure#1}
  44:     0x7fd43bff8f7a - rustc_lint[c1072c7a935321f8]::late::check_crate
  45:     0x7fd43b3638da - rustc_interface[4728fac6abb1a1aa]::passes::analysis
  46:     0x7fd43b363009 - rustc_query_impl[f52eeba12e8a164a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f52eeba12e8a164a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d85aae3cf006bd8]::query::erase::Erased<[u8; 0usize]>>
  47:     0x7fd43c3d3d91 - rustc_query_system[54a10b0b4f070675]::query::plumbing::try_execute_query::<rustc_query_impl[f52eeba12e8a164a]::DynamicConfig<rustc_query_system[54a10b0b4f070675]::query::caches::SingleCache<rustc_middle[8d85aae3cf006bd8]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[f52eeba12e8a164a]::plumbing::QueryCtxt, false>
  48:     0x7fd43c3d3b7c - rustc_query_impl[f52eeba12e8a164a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  49:     0x7fd43c5b31d1 - <rustc_interface[4728fac6abb1a1aa]::passes::create_and_enter_global_ctxt<core[ea2bd7cd219b3eb9]::option::Option<rustc_interface[4728fac6abb1a1aa]::queries::Linker>, rustc_driver_impl[b96920060a9f9ce8]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[ea2bd7cd219b3eb9]::ops::function::FnOnce<(&rustc_session[a8d494af7dba883f]::session::Session, rustc_middle[8d85aae3cf006bd8]::ty::context::CurrentGcx, alloc[d48b8b032ee4278d]::sync::Arc<rustc_data_structures[80b3ed06db703e49]::jobserver::Proxy>, &std[8cc15e19e2a5acfa]::sync::once_lock::OnceLock<rustc_middle[8d85aae3cf006bd8]::ty::context::GlobalCtxt>, &rustc_data_structures[80b3ed06db703e49]::sync::worker_local::WorkerLocal<rustc_middle[8d85aae3cf006bd8]::arena::Arena>, &rustc_data_structures[80b3ed06db703e49]::sync::worker_local::WorkerLocal<rustc_hir[f8bf578c86c342b0]::Arena>, rustc_driver_impl[b96920060a9f9ce8]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  50:     0x7fd43c3e73eb - rustc_interface[4728fac6abb1a1aa]::interface::run_compiler::<(), rustc_driver_impl[b96920060a9f9ce8]::run_compiler::{closure#0}>::{closure#1}
  51:     0x7fd43c436dbe - std[8cc15e19e2a5acfa]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4728fac6abb1a1aa]::util::run_in_thread_with_globals<rustc_interface[4728fac6abb1a1aa]::util::run_in_thread_pool_with_globals<rustc_interface[4728fac6abb1a1aa]::interface::run_compiler<(), rustc_driver_impl[b96920060a9f9ce8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  52:     0x7fd43c4372e0 - <std[8cc15e19e2a5acfa]::thread::lifecycle::spawn_unchecked<rustc_interface[4728fac6abb1a1aa]::util::run_in_thread_with_globals<rustc_interface[4728fac6abb1a1aa]::util::run_in_thread_pool_with_globals<rustc_interface[4728fac6abb1a1aa]::interface::run_compiler<(), rustc_driver_impl[b96920060a9f9ce8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[ea2bd7cd219b3eb9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  53:     0x7fd43c43816c - <std[8cc15e19e2a5acfa]::sys::thread::unix::Thread>::new::thread_start
  54:     0x7fd435c9698b - <unknown>
  55:     0x7fd435d1a9cc - <unknown>
  56:                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.95.0-nightly (474276961 2026-01-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(min_generic_const_args) -Z dump-mir-dir=dir

query stack during panic:
#0 [generics_of] computing generics of ``
#1 [dyn_compatibility_violations] determining dyn-compatibility of trait `CollectArray`
#2 [is_dyn_compatible] checking if trait `CollectArray` is dyn-compatible
#3 [lint_mod] linting top-level module
#4 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 1 previous error; 3 warnings emitted


@rustbot label +F-min_generic_const_args

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.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.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions