Skip to content

[ICE]: can't type-check body of DefId #153735

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: -Znext-solver=globally
#![feature(min_generic_const_args)]
#![feature(generic_const_exprs)]
type const INC = usize;

const ARR: [usize; 1] = [0; INC];

original:

#![feature(min_generic_const_args)]
#![feature(generic_const_exprs)]
type const INC = usize;

const ARR: [usize; 1] = [0; INC];
fn main() {}

Version information

rustc 1.96.0-nightly (3b1b0ef4d 2026-03-11)
binary: rustc
commit-hash: 3b1b0ef4d80d3117924d91352c8b6ca528708b3c
commit-date: 2026-03-11
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.0

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 -Znext-solver=globally

Program output

error[E0423]: expected value, found builtin type `usize`
 --> /tmp/icemaker_global_tempdir.cpvizYJ2IQkw/rustc_testrunner_tmpdir_reporting.3H0k3juZNyMv/mvce.rs:3:18
  |
3 | type const INC = usize;
  |                  ^^^^^ not a value

error: `-Znext-solver=globally` and `generic_const_exprs` are incompatible, using them at the same time is not allowed
 --> /tmp/icemaker_global_tempdir.cpvizYJ2IQkw/rustc_testrunner_tmpdir_reporting.3H0k3juZNyMv/mvce.rs:2:12
  |
2 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = help: remove one of these features

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.cpvizYJ2IQkw/rustc_testrunner_tmpdir_reporting.3H0k3juZNyMv/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: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.cpvizYJ2IQkw/rustc_testrunner_tmpdir_reporting.3H0k3juZNyMv/mvce.rs:2:12
  |
2 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.cpvizYJ2IQkw/rustc_testrunner_tmpdir_reporting.3H0k3juZNyMv/mvce.rs:5:34
  |
5 | const ARR: [usize; 1] = [0; INC];
  |                                  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.cpvizYJ2IQkw/rustc_testrunner_tmpdir_reporting.3H0k3juZNyMv/mvce.rs`

error: missing type for `const` item
 --> /tmp/icemaker_global_tempdir.cpvizYJ2IQkw/rustc_testrunner_tmpdir_reporting.3H0k3juZNyMv/mvce.rs:3:15
  |
3 | type const INC = usize;
  |               ^
  |
help: provide a type for the item
  |
3 | type const INC: <type> = usize;
  |               ++++++++

error: internal compiler error: /rustc-dev/3b1b0ef4d80d3117924d91352c8b6ca528708b3c/compiler/rustc_hir_typeck/src/lib.rs:120:9: can't type-check body of DefId(0:3 ~ mvce[d978]::INC)
 --> /tmp/icemaker_global_tempdir.cpvizYJ2IQkw/rustc_testrunner_tmpdir_reporting.3H0k3juZNyMv/mvce.rs:3:1
  |
3 | type const INC = usize;
  | ^^^^^^^^^^^^^^


thread 'rustc' (779442) panicked at /rustc-dev/3b1b0ef4d80d3117924d91352c8b6ca528708b3c/compiler/rustc_hir_typeck/src/lib.rs:120:9:
Box<dyn Any>
stack backtrace:
   0:     0x7f239c9488db - <<std[98a29328132e9808]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[d6e61f80bd84b1aa]::fmt::Display>::fmt
   1:     0x7f239d01cd08 - core[d6e61f80bd84b1aa]::fmt::write
   2:     0x7f239c95f8e6 - <std[98a29328132e9808]::sys::stdio::unix::Stderr as std[98a29328132e9808]::io::Write>::write_fmt
   3:     0x7f239c91e9c8 - std[98a29328132e9808]::panicking::default_hook::{closure#0}
   4:     0x7f239c93bd53 - std[98a29328132e9808]::panicking::default_hook
   5:     0x7f239b936a0c - std[98a29328132e9808]::panicking::update_hook::<alloc[181a33ef8c443c3d]::boxed::Box<rustc_driver_impl[da6c6aa1c22ed2c8]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f239c93c032 - std[98a29328132e9808]::panicking::panic_with_hook
   7:     0x7f239b966b31 - std[98a29328132e9808]::panicking::begin_panic::<rustc_errors[97e0e08b3e2a9a96]::ExplicitBug>::{closure#0}
   8:     0x7f239b95f816 - std[98a29328132e9808]::sys::backtrace::__rust_end_short_backtrace::<std[98a29328132e9808]::panicking::begin_panic<rustc_errors[97e0e08b3e2a9a96]::ExplicitBug>::{closure#0}, !>
   9:     0x7f239b95d448 - std[98a29328132e9808]::panicking::begin_panic::<rustc_errors[97e0e08b3e2a9a96]::ExplicitBug>
  10:     0x7f239b9721a1 - <rustc_errors[97e0e08b3e2a9a96]::diagnostic::BugAbort as rustc_errors[97e0e08b3e2a9a96]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f239bf2800c - <rustc_errors[97e0e08b3e2a9a96]::DiagCtxtHandle>::span_bug::<rustc_span[2b7bdaa576714e8d]::span_encoding::Span, alloc[181a33ef8c443c3d]::string::String>
  12:     0x7f239bf4f4f6 - rustc_middle[c5a7798a8191db22]::util::bug::opt_span_bug_fmt::<rustc_span[2b7bdaa576714e8d]::span_encoding::Span>::{closure#0}
  13:     0x7f239bf4f6a2 - rustc_middle[c5a7798a8191db22]::ty::context::tls::with_opt::<rustc_middle[c5a7798a8191db22]::util::bug::opt_span_bug_fmt<rustc_span[2b7bdaa576714e8d]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7f239bf3fe7b - rustc_middle[c5a7798a8191db22]::ty::context::tls::with_context_opt::<rustc_middle[c5a7798a8191db22]::ty::context::tls::with_opt<rustc_middle[c5a7798a8191db22]::util::bug::opt_span_bug_fmt<rustc_span[2b7bdaa576714e8d]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7f239a1de808 - rustc_middle[c5a7798a8191db22]::util::bug::span_bug_fmt::<rustc_span[2b7bdaa576714e8d]::span_encoding::Span>
  16:     0x7f239a4fe52b - rustc_hir_typeck[adb50ce8d6691c92]::typeck_with_inspect::{closure#0}::{closure#0}
  17:     0x7f239db69790 - rustc_hir_typeck[adb50ce8d6691c92]::typeck_with_inspect::{closure#0}
  18:     0x7f239db64032 - rustc_query_impl[62dde3202d61a64e]::query_impl::typeck::invoke_provider_fn::__rust_begin_short_backtrace
  19:     0x7f239d13ed29 - rustc_query_impl[62dde3202d61a64e]::execution::try_execute_query::<rustc_data_structures[3406ed04c82e19df]::vec_cache::VecCache<rustc_span[2b7bdaa576714e8d]::def_id::LocalDefId, rustc_middle[c5a7798a8191db22]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[c5a7798a8191db22]::dep_graph::graph::DepNodeIndex>, false>
  20:     0x7f239d13e6c3 - rustc_query_impl[62dde3202d61a64e]::query_impl::typeck::execute_query_non_incr::__rust_end_short_backtrace
  21:     0x7f239d45d8b7 - rustc_mir_build[cafd22c32640f38e]::thir::pattern::check_match::check_match
  22:     0x7f239d45cd19 - rustc_query_impl[62dde3202d61a64e]::query_impl::check_match::invoke_provider_fn::__rust_begin_short_backtrace
  23:     0x7f239d59567f - rustc_query_impl[62dde3202d61a64e]::execution::try_execute_query::<rustc_data_structures[3406ed04c82e19df]::vec_cache::VecCache<rustc_span[2b7bdaa576714e8d]::def_id::LocalDefId, rustc_middle[c5a7798a8191db22]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[c5a7798a8191db22]::dep_graph::graph::DepNodeIndex>, false>
  24:     0x7f239d595376 - rustc_query_impl[62dde3202d61a64e]::query_impl::check_match::execute_query_non_incr::__rust_end_short_backtrace
  25:     0x7f239dbef30b - rustc_mir_build[cafd22c32640f38e]::builder::build_mir_inner_impl
  26:     0x7f239d00b5aa - rustc_mir_transform[6168f73e22c1ef49]::mir_built
  27:     0x7f239d13ed29 - rustc_query_impl[62dde3202d61a64e]::execution::try_execute_query::<rustc_data_structures[3406ed04c82e19df]::vec_cache::VecCache<rustc_span[2b7bdaa576714e8d]::def_id::LocalDefId, rustc_middle[c5a7798a8191db22]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[c5a7798a8191db22]::dep_graph::graph::DepNodeIndex>, false>
  28:     0x7f239d13e783 - rustc_query_impl[62dde3202d61a64e]::query_impl::mir_built::execute_query_non_incr::__rust_end_short_backtrace
  29:     0x7f239d282003 - rustc_query_impl[62dde3202d61a64e]::query_impl::trivial_const::invoke_provider_fn::__rust_begin_short_backtrace
  30:     0x7f239d281480 - rustc_query_impl[62dde3202d61a64e]::execution::try_execute_query::<rustc_middle[c5a7798a8191db22]::query::caches::DefIdCache<rustc_middle[c5a7798a8191db22]::query::erase::ErasedData<[u8; 32usize]>>, false>
  31:     0x7f239d280ad0 - rustc_query_impl[62dde3202d61a64e]::query_impl::trivial_const::execute_query_non_incr::__rust_end_short_backtrace
  32:     0x7f239e080a15 - rustc_const_eval[c05eb92897bd2cc5]::const_eval::eval_queries::eval_to_allocation_raw_provider
  33:     0x7f239e07db98 - rustc_query_impl[62dde3202d61a64e]::query_impl::eval_to_allocation_raw::invoke_provider_fn::__rust_begin_short_backtrace
  34:     0x7f239e060683 - rustc_query_impl[62dde3202d61a64e]::execution::try_execute_query::<rustc_middle[c5a7798a8191db22]::query::caches::DefaultCache<rustc_middle[c5a7798a8191db22]::ty::PseudoCanonicalInput<rustc_middle[c5a7798a8191db22]::mir::interpret::GlobalId>, rustc_middle[c5a7798a8191db22]::query::erase::ErasedData<[u8; 24usize]>>, false>
  35:     0x7f239e060053 - rustc_query_impl[62dde3202d61a64e]::query_impl::eval_to_allocation_raw::execute_query_non_incr::__rust_end_short_backtrace
  36:     0x7f239e05dc13 - rustc_const_eval[c05eb92897bd2cc5]::const_eval::valtrees::eval_to_valtree
  37:     0x7f239e05d9e6 - <rustc_const_eval[c05eb92897bd2cc5]::provide::{closure#0} as core[d6e61f80bd84b1aa]::ops::function::FnOnce<(rustc_middle[c5a7798a8191db22]::ty::context::TyCtxt, rustc_middle[c5a7798a8191db22]::ty::PseudoCanonicalInput<rustc_middle[c5a7798a8191db22]::mir::interpret::GlobalId>)>>::call_once
  38:     0x7f239e05d99c - rustc_query_impl[62dde3202d61a64e]::query_impl::eval_to_valtree::invoke_provider_fn::__rust_begin_short_backtrace
  39:     0x7f239d8f4515 - rustc_query_impl[62dde3202d61a64e]::execution::try_execute_query::<rustc_middle[c5a7798a8191db22]::query::caches::DefaultCache<rustc_middle[c5a7798a8191db22]::ty::PseudoCanonicalInput<rustc_middle[c5a7798a8191db22]::mir::interpret::GlobalId>, rustc_middle[c5a7798a8191db22]::query::erase::ErasedData<[u8; 16usize]>>, false>
  40:     0x7f239d8f4118 - rustc_query_impl[62dde3202d61a64e]::query_impl::eval_to_valtree::execute_query_non_incr::__rust_end_short_backtrace
  41:     0x7f239a04f446 - <rustc_middle[c5a7798a8191db22]::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  42:     0x7f239d328fc6 - rustc_trait_selection[3a251dd4a743a455]::traits::try_evaluate_const
  43:     0x7f239b1a6015 - rustc_trait_selection[3a251dd4a743a455]::traits::evaluate_const
  44:     0x7f239dafbdef - <rustc_hir_typeck[adb50ce8d6691c92]::fn_ctxt::FnCtxt>::try_structurally_resolve_const
  45:     0x7f239dafbfbd - <rustc_hir_typeck[adb50ce8d6691c92]::fn_ctxt::FnCtxt>::check_expr_repeat
  46:     0x7f239d2ce191 - <rustc_hir_typeck[adb50ce8d6691c92]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  47:     0x7f239db68118 - rustc_hir_typeck[adb50ce8d6691c92]::typeck_with_inspect::{closure#0}
  48:     0x7f239db64032 - rustc_query_impl[62dde3202d61a64e]::query_impl::typeck::invoke_provider_fn::__rust_begin_short_backtrace
  49:     0x7f239d13ed29 - rustc_query_impl[62dde3202d61a64e]::execution::try_execute_query::<rustc_data_structures[3406ed04c82e19df]::vec_cache::VecCache<rustc_span[2b7bdaa576714e8d]::def_id::LocalDefId, rustc_middle[c5a7798a8191db22]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[c5a7798a8191db22]::dep_graph::graph::DepNodeIndex>, false>
  50:     0x7f239d13e6c3 - rustc_query_impl[62dde3202d61a64e]::query_impl::typeck::execute_query_non_incr::__rust_end_short_backtrace
  51:     0x7f239d45d8b7 - rustc_mir_build[cafd22c32640f38e]::thir::pattern::check_match::check_match
  52:     0x7f239d45cd19 - rustc_query_impl[62dde3202d61a64e]::query_impl::check_match::invoke_provider_fn::__rust_begin_short_backtrace
  53:     0x7f239d59567f - rustc_query_impl[62dde3202d61a64e]::execution::try_execute_query::<rustc_data_structures[3406ed04c82e19df]::vec_cache::VecCache<rustc_span[2b7bdaa576714e8d]::def_id::LocalDefId, rustc_middle[c5a7798a8191db22]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[c5a7798a8191db22]::dep_graph::graph::DepNodeIndex>, false>
  54:     0x7f239d595376 - rustc_query_impl[62dde3202d61a64e]::query_impl::check_match::execute_query_non_incr::__rust_end_short_backtrace
  55:     0x7f239dbef30b - rustc_mir_build[cafd22c32640f38e]::builder::build_mir_inner_impl
  56:     0x7f239d00b5aa - rustc_mir_transform[6168f73e22c1ef49]::mir_built
  57:     0x7f239d13ed29 - rustc_query_impl[62dde3202d61a64e]::execution::try_execute_query::<rustc_data_structures[3406ed04c82e19df]::vec_cache::VecCache<rustc_span[2b7bdaa576714e8d]::def_id::LocalDefId, rustc_middle[c5a7798a8191db22]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[c5a7798a8191db22]::dep_graph::graph::DepNodeIndex>, false>
  58:     0x7f239d13e783 - rustc_query_impl[62dde3202d61a64e]::query_impl::mir_built::execute_query_non_incr::__rust_end_short_backtrace
  59:     0x7f239d282003 - rustc_query_impl[62dde3202d61a64e]::query_impl::trivial_const::invoke_provider_fn::__rust_begin_short_backtrace
  60:     0x7f239d281480 - rustc_query_impl[62dde3202d61a64e]::execution::try_execute_query::<rustc_middle[c5a7798a8191db22]::query::caches::DefIdCache<rustc_middle[c5a7798a8191db22]::query::erase::ErasedData<[u8; 32usize]>>, false>
  61:     0x7f239d280ad0 - rustc_query_impl[62dde3202d61a64e]::query_impl::trivial_const::execute_query_non_incr::__rust_end_short_backtrace
  62:     0x7f239e05ed53 - rustc_const_eval[c05eb92897bd2cc5]::const_eval::eval_queries::eval_to_const_value_raw_provider
  63:     0x7f239e05ea9c - rustc_query_impl[62dde3202d61a64e]::query_impl::eval_to_const_value_raw::invoke_provider_fn::__rust_begin_short_backtrace
  64:     0x7f239e060582 - rustc_query_impl[62dde3202d61a64e]::execution::try_execute_query::<rustc_middle[c5a7798a8191db22]::query::caches::DefaultCache<rustc_middle[c5a7798a8191db22]::ty::PseudoCanonicalInput<rustc_middle[c5a7798a8191db22]::mir::interpret::GlobalId>, rustc_middle[c5a7798a8191db22]::query::erase::ErasedData<[u8; 24usize]>>, false>
  65:     0x7f239e06010b - rustc_query_impl[62dde3202d61a64e]::query_impl::eval_to_const_value_raw::execute_query_non_incr::__rust_end_short_backtrace
  66:     0x7f239da3cfe0 - <rustc_middle[c5a7798a8191db22]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[fb7797e3d1a18a57]::check_crate::{closure#2}>::{closure#0}
  67:     0x7f239da3c635 - rustc_hir_analysis[fb7797e3d1a18a57]::check_crate
  68:     0x7f239d1400d3 - rustc_interface[165454881ff1a59b]::passes::analysis
  69:     0x7f239e2a2409 - rustc_query_impl[62dde3202d61a64e]::execution::try_execute_query::<rustc_middle[c5a7798a8191db22]::query::caches::SingleCache<rustc_middle[c5a7798a8191db22]::query::erase::ErasedData<[u8; 0usize]>>, false>
  70:     0x7f239e2a20e9 - rustc_query_impl[62dde3202d61a64e]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  71:     0x7f239e256248 - rustc_interface[165454881ff1a59b]::interface::run_compiler::<(), rustc_driver_impl[da6c6aa1c22ed2c8]::run_compiler::{closure#0}>::{closure#1}
  72:     0x7f239e27b1fe - std[98a29328132e9808]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[165454881ff1a59b]::util::run_in_thread_with_globals<rustc_interface[165454881ff1a59b]::util::run_in_thread_pool_with_globals<rustc_interface[165454881ff1a59b]::interface::run_compiler<(), rustc_driver_impl[da6c6aa1c22ed2c8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  73:     0x7f239e27baa0 - <std[98a29328132e9808]::thread::lifecycle::spawn_unchecked<rustc_interface[165454881ff1a59b]::util::run_in_thread_with_globals<rustc_interface[165454881ff1a59b]::util::run_in_thread_pool_with_globals<rustc_interface[165454881ff1a59b]::interface::run_compiler<(), rustc_driver_impl[da6c6aa1c22ed2c8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[d6e61f80bd84b1aa]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  74:     0x7f239e27c92c - <std[98a29328132e9808]::sys::thread::unix::Thread>::new::thread_start
  75:     0x7f2397ca598b - <unknown>
  76:     0x7f2397d29a0c - <unknown>
  77:                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 (3b1b0ef4d 2026-03-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z next-solver=globally -Z dump-mir-dir=dir

query stack during panic:
#0 [typeck] type-checking `INC`
#1 [check_match] match-checking `INC`
#2 [mir_built] building MIR for `INC`
#3 [trivial_const] checking if `INC` is a trivial const
#4 [eval_to_allocation_raw] const-evaluating + checking `INC`
#5 [eval_to_valtree] evaluating type-level constant
#6 [typeck] type-checking `ARR`
#7 [check_match] match-checking `ARR`
#8 [mir_built] building MIR for `ARR`
#9 [trivial_const] checking if `ARR` is a trivial const
#10 [eval_to_const_value_raw] simplifying constant for the type system `ARR`
#11 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 5 previous errors; 2 warnings emitted

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

@rustbot label +F-min_generic_const_args +F-generic_const_exprs +WG-trait-system-refactor

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`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.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)

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