Skip to content

ICE: can't type-check body of DefId #151246

@matthiaskrgr

Description

@matthiaskrgr
//@compile-flags: -Clink-dead-code=true
#![feature(min_generic_const_args)]
#[type_const]
const TYPE_CONST: usize = 0;
fn main() {}

Version information

rustc 1.94.0-nightly (9f6cd6def 2026-01-17)
binary: rustc
commit-hash: 9f6cd6defbd7ef13f6777aa8e43b14d69f0a830a
commit-date: 2026-01-17
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8

Possibly related line of code:

let id = tcx.local_def_id_to_hir_id(def_id);
let node = tcx.hir_node(id);
let span = tcx.def_span(def_id);
// Figure out what primary body this item has.
let body_id = node.body_id().unwrap_or_else(|| {
span_bug!(span, "can't type-check body of {:?}", def_id);
});
let body = tcx.hir_body(body_id);
let param_env = tcx.param_env(def_id);
let root_ctxt = TypeckRootCtxt::new(tcx, def_id);

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Clink-dead-code=true

Program output

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.9vWmiHIgVjAb/rustc_testrunner_tmpdir_reporting.4W5Kdpo8I2nF/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

warning: constant `TYPE_CONST` is never used
 --> /tmp/icemaker_global_tempdir.9vWmiHIgVjAb/rustc_testrunner_tmpdir_reporting.4W5Kdpo8I2nF/mvce.rs:3:7
  |
3 | const TYPE_CONST: usize = 0;
  |       ^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

error: internal compiler error: /rustc-dev/9f6cd6defbd7ef13f6777aa8e43b14d69f0a830a/compiler/rustc_hir_typeck/src/lib.rs:124:9: can't type-check body of DefId(0:3 ~ mvce[19d4]::TYPE_CONST)
 --> /tmp/icemaker_global_tempdir.9vWmiHIgVjAb/rustc_testrunner_tmpdir_reporting.4W5Kdpo8I2nF/mvce.rs:3:1
  |
3 | const TYPE_CONST: usize = 0;
  | ^^^^^^^^^^^^^^^^^^^^^^^


thread 'rustc' (1561141) panicked at /rustc-dev/9f6cd6defbd7ef13f6777aa8e43b14d69f0a830a/compiler/rustc_hir_typeck/src/lib.rs:124:9:
Box<dyn Any>
stack backtrace:
   0:     0x7f74d3e38413 - <<std[5563efb7f247ea34]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[6067e6f2671c3dd]::fmt::Display>::fmt
   1:     0x7f74d440e2c8 - core[6067e6f2671c3dd]::fmt::write
   2:     0x7f74d3e4ee06 - <std[5563efb7f247ea34]::sys::stdio::unix::Stderr as std[5563efb7f247ea34]::io::Write>::write_fmt
   3:     0x7f74d3e0e488 - std[5563efb7f247ea34]::panicking::default_hook::{closure#0}
   4:     0x7f74d3e2bb43 - std[5563efb7f247ea34]::panicking::default_hook
   5:     0x7f74d2dffeba - std[5563efb7f247ea34]::panicking::update_hook::<alloc[fff5fa3571839cce]::boxed::Box<rustc_driver_impl[c32a203bb6815f6e]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f74d3e2be22 - std[5563efb7f247ea34]::panicking::panic_with_hook
   7:     0x7f74d2e3cef1 - std[5563efb7f247ea34]::panicking::begin_panic::<rustc_errors[1785ae46fd47b5e]::ExplicitBug>::{closure#0}
   8:     0x7f74d2e2d316 - std[5563efb7f247ea34]::sys::backtrace::__rust_end_short_backtrace::<std[5563efb7f247ea34]::panicking::begin_panic<rustc_errors[1785ae46fd47b5e]::ExplicitBug>::{closure#0}, !>
   9:     0x7f74d2e2a7e9 - std[5563efb7f247ea34]::panicking::begin_panic::<rustc_errors[1785ae46fd47b5e]::ExplicitBug>
  10:     0x7f74d2e5ac31 - <rustc_errors[1785ae46fd47b5e]::diagnostic::BugAbort as rustc_errors[1785ae46fd47b5e]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f74d33e8d1c - <rustc_errors[1785ae46fd47b5e]::DiagCtxtHandle>::span_bug::<rustc_span[657f64d7c3ae02a8]::span_encoding::Span, alloc[fff5fa3571839cce]::string::String>
  12:     0x7f74d340b8a6 - rustc_middle[38e34eab80c5dffd]::util::bug::opt_span_bug_fmt::<rustc_span[657f64d7c3ae02a8]::span_encoding::Span>::{closure#0}
  13:     0x7f74d340ba52 - rustc_middle[38e34eab80c5dffd]::ty::context::tls::with_opt::<rustc_middle[38e34eab80c5dffd]::util::bug::opt_span_bug_fmt<rustc_span[657f64d7c3ae02a8]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7f74d33fcb6b - rustc_middle[38e34eab80c5dffd]::ty::context::tls::with_context_opt::<rustc_middle[38e34eab80c5dffd]::ty::context::tls::with_opt<rustc_middle[38e34eab80c5dffd]::util::bug::opt_span_bug_fmt<rustc_span[657f64d7c3ae02a8]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7f74d0cf4948 - rustc_middle[38e34eab80c5dffd]::util::bug::span_bug_fmt::<rustc_span[657f64d7c3ae02a8]::span_encoding::Span>
  16:     0x7f74d191dffb - rustc_hir_typeck[a2c5f79160f65757]::typeck_with_inspect::{closure#0}::{closure#0}
  17:     0x7f74d51ab2f8 - rustc_hir_typeck[a2c5f79160f65757]::typeck_with_inspect::{closure#0}
  18:     0x7f74d51a5ab4 - rustc_query_impl[c90c15b3cf9dcc59]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c90c15b3cf9dcc59]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[38e34eab80c5dffd]::query::erase::Erased<[u8; 8usize]>>
  19:     0x7f74d455582a - rustc_query_system[e01d75cc3ad2d928]::query::plumbing::try_execute_query::<rustc_query_impl[c90c15b3cf9dcc59]::DynamicConfig<rustc_data_structures[c206126045f600c6]::vec_cache::VecCache<rustc_span[657f64d7c3ae02a8]::def_id::LocalDefId, rustc_middle[38e34eab80c5dffd]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[e01d75cc3ad2d928]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[c90c15b3cf9dcc59]::plumbing::QueryCtxt, false>
  20:     0x7f74d4555109 - rustc_query_impl[c90c15b3cf9dcc59]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  21:     0x7f74d48f880a - rustc_mir_build[8d8e66ec55b55418]::thir::pattern::check_match::check_match
  22:     0x7f74d48f7bd1 - rustc_query_impl[c90c15b3cf9dcc59]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c90c15b3cf9dcc59]::query_impl::check_match::dynamic_query::{closure#2}::{closure#0}, rustc_middle[38e34eab80c5dffd]::query::erase::Erased<[u8; 1usize]>>
  23:     0x7f74d4bbfe38 - rustc_query_system[e01d75cc3ad2d928]::query::plumbing::try_execute_query::<rustc_query_impl[c90c15b3cf9dcc59]::DynamicConfig<rustc_data_structures[c206126045f600c6]::vec_cache::VecCache<rustc_span[657f64d7c3ae02a8]::def_id::LocalDefId, rustc_middle[38e34eab80c5dffd]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[e01d75cc3ad2d928]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[c90c15b3cf9dcc59]::plumbing::QueryCtxt, false>
  24:     0x7f74d4bbfafd - rustc_query_impl[c90c15b3cf9dcc59]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace
  25:     0x7f74d4952b67 - rustc_mir_build[8d8e66ec55b55418]::builder::build_mir_inner_impl
  26:     0x7f74d4408dea - rustc_mir_transform[11b2c2a9f8c4b61b]::mir_built
  27:     0x7f74d4408db3 - rustc_query_impl[c90c15b3cf9dcc59]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c90c15b3cf9dcc59]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[38e34eab80c5dffd]::query::erase::Erased<[u8; 8usize]>>
  28:     0x7f74d455582a - rustc_query_system[e01d75cc3ad2d928]::query::plumbing::try_execute_query::<rustc_query_impl[c90c15b3cf9dcc59]::DynamicConfig<rustc_data_structures[c206126045f600c6]::vec_cache::VecCache<rustc_span[657f64d7c3ae02a8]::def_id::LocalDefId, rustc_middle[38e34eab80c5dffd]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[e01d75cc3ad2d928]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[c90c15b3cf9dcc59]::plumbing::QueryCtxt, false>
  29:     0x7f74d4555289 - rustc_query_impl[c90c15b3cf9dcc59]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7f74d459e511 - rustc_query_impl[c90c15b3cf9dcc59]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c90c15b3cf9dcc59]::query_impl::trivial_const::dynamic_query::{closure#2}::{closure#0}, rustc_middle[38e34eab80c5dffd]::query::erase::Erased<[u8; 32usize]>>
  31:     0x7f74d459bd97 - rustc_query_system[e01d75cc3ad2d928]::query::plumbing::try_execute_query::<rustc_query_impl[c90c15b3cf9dcc59]::DynamicConfig<rustc_query_system[e01d75cc3ad2d928]::query::caches::DefIdCache<rustc_middle[38e34eab80c5dffd]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[c90c15b3cf9dcc59]::plumbing::QueryCtxt, false>
  32:     0x7f74d459b620 - rustc_query_impl[c90c15b3cf9dcc59]::query_impl::trivial_const::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7f74d553403c - rustc_const_eval[cbdfe2fb56c8e13d]::const_eval::eval_queries::eval_to_const_value_raw_provider
  34:     0x7f74d5533d80 - rustc_query_impl[c90c15b3cf9dcc59]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c90c15b3cf9dcc59]::query_impl::eval_to_const_value_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[38e34eab80c5dffd]::query::erase::Erased<[u8; 24usize]>>
  35:     0x7f74d553298a - rustc_query_system[e01d75cc3ad2d928]::query::plumbing::try_execute_query::<rustc_query_impl[c90c15b3cf9dcc59]::DynamicConfig<rustc_query_system[e01d75cc3ad2d928]::query::caches::DefaultCache<rustc_middle[38e34eab80c5dffd]::ty::PseudoCanonicalInput<rustc_middle[38e34eab80c5dffd]::mir::interpret::GlobalId>, rustc_middle[38e34eab80c5dffd]::query::erase::Erased<[u8; 24usize]>>, false, true, false>, rustc_query_impl[c90c15b3cf9dcc59]::plumbing::QueryCtxt, false>
  36:     0x7f74d55324f3 - rustc_query_impl[c90c15b3cf9dcc59]::query_impl::eval_to_const_value_raw::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7f74d497ad43 - <rustc_middle[38e34eab80c5dffd]::ty::context::TyCtxt>::const_eval_global_id
  38:     0x7f74d497a241 - <rustc_middle[38e34eab80c5dffd]::ty::context::TyCtxt>::const_eval_poly
  39:     0x7f74d48bd4f1 - rustc_monomorphize[3a63ebbe3287590b]::collector::collect_roots
  40:     0x7f74d4e475c0 - rustc_monomorphize[3a63ebbe3287590b]::partitioning::collect_and_partition_mono_items
  41:     0x7f74d59380b2 - rustc_query_impl[c90c15b3cf9dcc59]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c90c15b3cf9dcc59]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[38e34eab80c5dffd]::query::erase::Erased<[u8; 24usize]>>
  42:     0x7f74d5938097 - <rustc_query_impl[c90c15b3cf9dcc59]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[6067e6f2671c3dd]::ops::function::FnOnce<(rustc_middle[38e34eab80c5dffd]::ty::context::TyCtxt, ())>>::call_once
  43:     0x7f74d5937c2f - rustc_query_system[e01d75cc3ad2d928]::query::plumbing::try_execute_query::<rustc_query_impl[c90c15b3cf9dcc59]::DynamicConfig<rustc_query_system[e01d75cc3ad2d928]::query::caches::SingleCache<rustc_middle[38e34eab80c5dffd]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[c90c15b3cf9dcc59]::plumbing::QueryCtxt, false>
  44:     0x7f74d59379d7 - rustc_query_impl[c90c15b3cf9dcc59]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7f74d580ad1a - rustc_codegen_ssa[be8935ddd9faa75c]::base::codegen_crate::<rustc_codegen_llvm[1e2e5a43e14090d5]::LlvmCodegenBackend>
  46:     0x7f74d58087fd - <rustc_codegen_llvm[1e2e5a43e14090d5]::LlvmCodegenBackend as rustc_codegen_ssa[be8935ddd9faa75c]::traits::backend::CodegenBackend>::codegen_crate
  47:     0x7f74d5786212 - <rustc_interface[8f5d8f9a48cb0e5b]::queries::Linker>::codegen_and_build_linker
  48:     0x7f74d5783819 - <rustc_interface[8f5d8f9a48cb0e5b]::passes::create_and_enter_global_ctxt<core[6067e6f2671c3dd]::option::Option<rustc_interface[8f5d8f9a48cb0e5b]::queries::Linker>, rustc_driver_impl[c32a203bb6815f6e]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[6067e6f2671c3dd]::ops::function::FnOnce<(&rustc_session[7ae56eb119035399]::session::Session, rustc_middle[38e34eab80c5dffd]::ty::context::CurrentGcx, alloc[fff5fa3571839cce]::sync::Arc<rustc_data_structures[c206126045f600c6]::jobserver::Proxy>, &std[5563efb7f247ea34]::sync::once_lock::OnceLock<rustc_middle[38e34eab80c5dffd]::ty::context::GlobalCtxt>, &rustc_data_structures[c206126045f600c6]::sync::worker_local::WorkerLocal<rustc_middle[38e34eab80c5dffd]::arena::Arena>, &rustc_data_structures[c206126045f600c6]::sync::worker_local::WorkerLocal<rustc_hir[fa6d62530edb3226]::Arena>, rustc_driver_impl[c32a203bb6815f6e]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  49:     0x7f74d5662c74 - rustc_interface[8f5d8f9a48cb0e5b]::interface::run_compiler::<(), rustc_driver_impl[c32a203bb6815f6e]::run_compiler::{closure#0}>::{closure#1}
  50:     0x7f74d55065ce - std[5563efb7f247ea34]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[8f5d8f9a48cb0e5b]::util::run_in_thread_with_globals<rustc_interface[8f5d8f9a48cb0e5b]::util::run_in_thread_pool_with_globals<rustc_interface[8f5d8f9a48cb0e5b]::interface::run_compiler<(), rustc_driver_impl[c32a203bb6815f6e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  51:     0x7f74d55063a0 - <std[5563efb7f247ea34]::thread::lifecycle::spawn_unchecked<rustc_interface[8f5d8f9a48cb0e5b]::util::run_in_thread_with_globals<rustc_interface[8f5d8f9a48cb0e5b]::util::run_in_thread_pool_with_globals<rustc_interface[8f5d8f9a48cb0e5b]::interface::run_compiler<(), rustc_driver_impl[c32a203bb6815f6e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[6067e6f2671c3dd]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  52:     0x7f74d5508546 - <std[5563efb7f247ea34]::sys::thread::unix::Thread>::new::thread_start
  53:     0x7f74cee9698b - <unknown>
  54:     0x7f74cef1a9cc - <unknown>
  55:                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.94.0-nightly (9f6cd6def 2026-01-17) running on x86_64-unknown-linux-gnu

note: compiler flags: -C link-dead-code=true -Z dump-mir-dir=dir

query stack during panic:
#0 [typeck] type-checking `TYPE_CONST`
#1 [check_match] match-checking `TYPE_CONST`
#2 [mir_built] building MIR for `TYPE_CONST`
#3 [trivial_const] checking if `TYPE_CONST` is a trivial const
#4 [eval_to_const_value_raw] simplifying constant for the type system `TYPE_CONST`
#5 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to 1 previous error; 2 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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions