Repository navigation
ICE: cannot call const_of_item on a non-type_const BodyId #148728
Copy link
Copy link
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-gca_min_const_items`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
auto-reduced (treereduce-rust):
#![feature(min_generic_const_args)]
const EXAMPLE: &[u8] = include_bytes!();
static BUF: [u8; EXAMPLE] = { arr };original:
//@compile-flags: -Zmir-opt-level=5 -Zvalidate-mir
#![feature(min_generic_const_args)]
const EXAMPLE: &[u8] = include_bytes!("/proc/cpuinfo");
static BUF: [u8; EXAMPLE] = { arr };
fn main() {
println!("/proc/cpuinfo", BUF.len());
}Version information
rustc 1.93.0-nightly (72b21e1a6 2025-11-08)
binary: rustc
commit-hash: 72b21e1a64dbbbb3b59ac7ce21363c366a894b79
commit-date: 2025-11-08
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.3
Possibly related line of code:
rust/compiler/rustc_hir_analysis/src/collect.rs
Lines 1598 to 1610 in 72b21e1
| span_bug!(tcx.def_span(def_id), "`const_of_item` expected a const or assoc const item") | |
| } | |
| }; | |
| let ct_arg = match ct_rhs { | |
| hir::ConstItemRhs::TypeConst(ct_arg) => ct_arg, | |
| hir::ConstItemRhs::Body(body_id) => { | |
| bug!("cannot call const_of_item on a non-type_const {body_id:?}") | |
| } | |
| }; | |
| let icx = ItemCtxt::new(tcx, def_id); | |
| let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id); | |
| let ct = icx | |
| .lowerer() |
Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zincremental-verify-ich=yes -Cincremental=<dir> -Cdebuginfo=2 -Clink-dead-code=true -Zvalidate-mir -Zquery-dep-graph -Zthreads=4 --edition=2024
Program output
error: include_bytes! takes 1 argument
--> /tmp/icemaker_global_tempdir.yBgXHzx7A8aP/rustc_testrunner_tmpdir_reporting.26gI3I7I9Tsb/mvce.rs:2:24
|
2 | const EXAMPLE: &[u8] = include_bytes!();
| ^^^^^^^^^^^^^^^^
error[E0425]: cannot find value `arr` in this scope
--> /tmp/icemaker_global_tempdir.yBgXHzx7A8aP/rustc_testrunner_tmpdir_reporting.26gI3I7I9Tsb/mvce.rs:4:31
|
4 | static BUF: [u8; EXAMPLE] = { arr };
| ^^^ help: a tuple variant with a similar name exists: `Err`
|
::: /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/result.rs:566:5
|
566 | Err(#[stable(feature = "rust1", since = "1.0.0")] E),
| --- similarly named tuple variant `Err` defined here
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.yBgXHzx7A8aP/rustc_testrunner_tmpdir_reporting.26gI3I7I9Tsb/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: unnecessary braces around assigned value
--> /tmp/icemaker_global_tempdir.yBgXHzx7A8aP/rustc_testrunner_tmpdir_reporting.26gI3I7I9Tsb/mvce.rs:4:29
|
4 | static BUF: [u8; EXAMPLE] = { arr };
| ^^ ^^
|
= note: `#[warn(unused_braces)]` (part of `#[warn(unused)]`) on by default
help: remove these braces
|
4 - static BUF: [u8; EXAMPLE] = { arr };
4 + static BUF: [u8; EXAMPLE] = arr;
|
error[E0601]: `main` function not found in crate `mvce`
--> /tmp/icemaker_global_tempdir.yBgXHzx7A8aP/rustc_testrunner_tmpdir_reporting.26gI3I7I9Tsb/mvce.rs:4:37
|
4 | static BUF: [u8; EXAMPLE] = { arr };
| ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.yBgXHzx7A8aP/rustc_testrunner_tmpdir_reporting.26gI3I7I9Tsb/mvce.rs`
error: internal compiler error: compiler/rustc_hir_analysis/src/collect.rs:1604:13: cannot call const_of_item on a non-type_const BodyId { hir_id: HirId(DefId(0:3 ~ mvce[4e7e]::EXAMPLE).6) }
thread 'rustc' (3116536) panicked at compiler/rustc_hir_analysis/src/collect.rs:1604:13:
Box<dyn Any>
stack backtrace:
0: 0x7fb5c1e71253 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hcca3c0a1d1647c59
1: 0x7fb5c2601afc - core::fmt::write::h4102dd63eb97ae71
2: 0x7fb5c1e25cd3 - std::io::Write::write_fmt::hb7012c2a8b8fd004
3: 0x7fb5c1e373d2 - std::sys::backtrace::BacktraceLock::print::he1cfc27585b288a1
4: 0x7fb5c1e3d429 - std::panicking::default_hook::{{closure}}::h56f78913e42eddcc
5: 0x7fb5c1e3cf53 - std::panicking::default_hook::hd9ae249ab356fc25
6: 0x7fb5c0e2f3d1 - std[155e3b79a2821849]::panicking::update_hook::<alloc[c4b61704c478c018]::boxed::Box<rustc_driver_impl[c3522bc1b3059489]::install_ice_hook::{closure#1}>>::{closure#0}
7: 0x7fb5c1e3d84f - std::panicking::panic_with_hook::ha085a42b834d510b
8: 0x7fb5c0e6b951 - std[155e3b79a2821849]::panicking::begin_panic::<rustc_errors[cff983c337c2971c]::ExplicitBug>::{closure#0}
9: 0x7fb5c0e5ddf6 - std[155e3b79a2821849]::sys::backtrace::__rust_end_short_backtrace::<std[155e3b79a2821849]::panicking::begin_panic<rustc_errors[cff983c337c2971c]::ExplicitBug>::{closure#0}, !>
10: 0x7fb5c0e5b549 - std[155e3b79a2821849]::panicking::begin_panic::<rustc_errors[cff983c337c2971c]::ExplicitBug>
11: 0x7fb5c0e89fc1 - <rustc_errors[cff983c337c2971c]::diagnostic::BugAbort as rustc_errors[cff983c337c2971c]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
12: 0x7fb5c141272a - rustc_middle[3cd47588377ceff1]::util::bug::opt_span_bug_fmt::<rustc_span[7edc6483ad12113b]::span_encoding::Span>::{closure#0}
13: 0x7fb5c14128aa - rustc_middle[3cd47588377ceff1]::ty::context::tls::with_opt::<rustc_middle[3cd47588377ceff1]::util::bug::opt_span_bug_fmt<rustc_span[7edc6483ad12113b]::span_encoding::Span>::{closure#0}, !>::{closure#0}
14: 0x7fb5c14032bb - rustc_middle[3cd47588377ceff1]::ty::context::tls::with_context_opt::<rustc_middle[3cd47588377ceff1]::ty::context::tls::with_opt<rustc_middle[3cd47588377ceff1]::util::bug::opt_span_bug_fmt<rustc_span[7edc6483ad12113b]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
15: 0x7fb5bf1a4880 - rustc_middle[3cd47588377ceff1]::util::bug::bug_fmt
16: 0x7fb5c0fddd0f - rustc_hir_analysis[8bda365d173e2f68]::collect::const_of_item
17: 0x7fb5c18104f3 - rustc_query_impl[79ff6c9466bd5884]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[79ff6c9466bd5884]::query_impl::const_of_item::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3cd47588377ceff1]::query::erase::Erased<[u8; 8usize]>>
18: 0x7fb5c2959a01 - rustc_query_system[aa5312ee5c7c29d1]::query::plumbing::try_execute_query::<rustc_query_impl[79ff6c9466bd5884]::DynamicConfig<rustc_query_system[aa5312ee5c7c29d1]::query::caches::DefIdCache<rustc_middle[3cd47588377ceff1]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[79ff6c9466bd5884]::plumbing::QueryCtxt, true>
19: 0x7fb5c18aa037 - rustc_query_impl[79ff6c9466bd5884]::query_impl::const_of_item::get_query_incr::__rust_end_short_backtrace
20: 0x7fb5c3a631dd - <rustc_trait_selection[bfcb0e0196f4a7bc]::traits::normalize::AssocTypeNormalizer>::normalize_free_alias::{closure#0}
21: 0x7fb5c281d1aa - <rustc_trait_selection[bfcb0e0196f4a7bc]::traits::normalize::AssocTypeNormalizer as rustc_type_ir[f7821b71b42b6d71]::fold::TypeFolder<rustc_middle[3cd47588377ceff1]::ty::context::TyCtxt>>::fold_const
22: 0x7fb5c281f7d7 - <rustc_middle[3cd47588377ceff1]::ty::Ty as rustc_type_ir[f7821b71b42b6d71]::fold::TypeSuperFoldable<rustc_middle[3cd47588377ceff1]::ty::context::TyCtxt>>::super_fold_with::<rustc_trait_selection[bfcb0e0196f4a7bc]::traits::normalize::AssocTypeNormalizer>
23: 0x7fb5c2eec2bd - <rustc_hir_analysis[8bda365d173e2f68]::check::wfcheck::WfCheckingCtxt>::deeply_normalize::<rustc_middle[3cd47588377ceff1]::ty::Ty>
24: 0x7fb5c2f0a0ee - rustc_hir_analysis[8bda365d173e2f68]::check::wfcheck::check_static_item
25: 0x7fb5c3020237 - rustc_hir_analysis[8bda365d173e2f68]::collect::type_of::type_of
26: 0x7fb5c261d926 - rustc_query_impl[79ff6c9466bd5884]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[79ff6c9466bd5884]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3cd47588377ceff1]::query::erase::Erased<[u8; 8usize]>>
27: 0x7fb5c2959a01 - rustc_query_system[aa5312ee5c7c29d1]::query::plumbing::try_execute_query::<rustc_query_impl[79ff6c9466bd5884]::DynamicConfig<rustc_query_system[aa5312ee5c7c29d1]::query::caches::DefIdCache<rustc_middle[3cd47588377ceff1]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[79ff6c9466bd5884]::plumbing::QueryCtxt, true>
28: 0x7fb5c2959146 - rustc_query_impl[79ff6c9466bd5884]::query_impl::type_of::get_query_incr::__rust_end_short_backtrace
29: 0x7fb5c2e193f6 - rustc_hir_analysis[8bda365d173e2f68]::check::check::check_item_type
30: 0x7fb5c2e1385c - rustc_hir_analysis[8bda365d173e2f68]::check::wfcheck::check_well_formed
31: 0x7fb5c2e13835 - rustc_query_impl[79ff6c9466bd5884]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[79ff6c9466bd5884]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3cd47588377ceff1]::query::erase::Erased<[u8; 1usize]>>
32: 0x7fb5c2949e61 - rustc_query_system[aa5312ee5c7c29d1]::query::plumbing::try_execute_query::<rustc_query_impl[79ff6c9466bd5884]::DynamicConfig<rustc_data_structures[d0f0f5062ba2726]::vec_cache::VecCache<rustc_span[7edc6483ad12113b]::def_id::LocalDefId, rustc_middle[3cd47588377ceff1]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[aa5312ee5c7c29d1]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[79ff6c9466bd5884]::plumbing::QueryCtxt, true>
33: 0x7fb5c294c62d - rustc_query_impl[79ff6c9466bd5884]::query_impl::check_well_formed::get_query_incr::__rust_end_short_backtrace
34: 0x7fb5c0f5b4eb - rustc_middle[3cd47588377ceff1]::query::inner::query_ensure_error_guaranteed::<rustc_data_structures[d0f0f5062ba2726]::vec_cache::VecCache<rustc_span[7edc6483ad12113b]::def_id::LocalDefId, rustc_middle[3cd47588377ceff1]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[aa5312ee5c7c29d1]::dep_graph::graph::DepNodeIndex>, ()>
35: 0x7fb5c0f6c69e - rustc_data_structures[d0f0f5062ba2726]::sync::parallel::par_slice::par_rec::<&rustc_hir[b47be72a75dd08a9]::hir::ItemId, rustc_data_structures[d0f0f5062ba2726]::sync::parallel::try_par_for_each_in<&[rustc_hir[b47be72a75dd08a9]::hir::ItemId], rustc_span[7edc6483ad12113b]::ErrorGuaranteed, <rustc_middle[3cd47588377ceff1]::hir::ModuleItems>::par_items<rustc_hir_analysis[8bda365d173e2f68]::check::wfcheck::check_type_wf::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>
36: 0x7fb5c102ea87 - <rustc_thread_pool[234d490567d5602b]::job::StackJob<rustc_thread_pool[234d490567d5602b]::latch::SpinLatch, rustc_thread_pool[234d490567d5602b]::join::join_context<rustc_thread_pool[234d490567d5602b]::join::join::call<(), rustc_data_structures[d0f0f5062ba2726]::sync::parallel::par_slice::par_rec<&rustc_hir[b47be72a75dd08a9]::hir::ItemId, rustc_data_structures[d0f0f5062ba2726]::sync::parallel::try_par_for_each_in<&[rustc_hir[b47be72a75dd08a9]::hir::ItemId], rustc_span[7edc6483ad12113b]::ErrorGuaranteed, <rustc_middle[3cd47588377ceff1]::hir::ModuleItems>::par_items<rustc_hir_analysis[8bda365d173e2f68]::check::wfcheck::check_type_wf::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>::{closure#1}>::{closure#0}, rustc_thread_pool[234d490567d5602b]::join::join::call<(), rustc_data_structures[d0f0f5062ba2726]::sync::parallel::par_slice::par_rec<&rustc_hir[b47be72a75dd08a9]::hir::ItemId, rustc_data_structures[d0f0f5062ba2726]::sync::parallel::try_par_for_each_in<&[rustc_hir[b47be72a75dd08a9]::hir::ItemId], rustc_span[7edc6483ad12113b]::ErrorGuaranteed, <rustc_middle[3cd47588377ceff1]::hir::ModuleItems>::par_items<rustc_hir_analysis[8bda365d173e2f68]::check::wfcheck::check_type_wf::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>::{closure#2}>::{closure#0}, (), ()>::{closure#0}::{closure#0}, ()> as rustc_thread_pool[234d490567d5602b]::job::Job>::execute
37: 0x7fb5c1b47def - <rustc_thread_pool[234d490567d5602b]::registry::WorkerThread>::wait_or_steal_until_cold
38: 0x7fb5c1b46891 - <rustc_thread_pool[234d490567d5602b]::registry::ThreadBuilder>::run
39: 0x7fb5c0e2744d - std[155e3b79a2821849]::sys::backtrace::__rust_begin_short_backtrace::<<rustc_thread_pool[234d490567d5602b]::ThreadPoolBuilder>::build_scoped<rustc_interface[dd019e0167f5b788]::util::run_in_thread_pool_with_globals<rustc_interface[dd019e0167f5b788]::interface::run_compiler<(), rustc_driver_impl[c3522bc1b3059489]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#0}, rustc_interface[dd019e0167f5b788]::util::run_in_thread_pool_with_globals<rustc_interface[dd019e0167f5b788]::interface::run_compiler<(), rustc_driver_impl[c3522bc1b3059489]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#1}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
40: 0x7fb5c0e32a02 - <<std[155e3b79a2821849]::thread::Builder>::spawn_unchecked_<<rustc_thread_pool[234d490567d5602b]::ThreadPoolBuilder>::build_scoped<rustc_interface[dd019e0167f5b788]::util::run_in_thread_pool_with_globals<rustc_interface[dd019e0167f5b788]::interface::run_compiler<(), rustc_driver_impl[c3522bc1b3059489]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#0}, rustc_interface[dd019e0167f5b788]::util::run_in_thread_pool_with_globals<rustc_interface[dd019e0167f5b788]::interface::run_compiler<(), rustc_driver_impl[c3522bc1b3059489]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#5}::{closure#0}::{closure#1}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>::{closure#1} as core[e19504c39fe2c26b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
41: 0x7fb5c344632f - std::sys::thread::unix::Thread::new::thread_start::h6124ec86ff25f360
42: 0x7fb5bce969cb - <unknown>
43: 0x7fb5bcf1aa0c - <unknown>
44: 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.93.0-nightly (72b21e1a6 2025-11-08) running on x86_64-unknown-linux-gnu
note: compiler flags: -Z incremental-verify-ich=yes -C incremental=[REDACTED] -C debuginfo=2 -C link-dead-code=true -Z validate-mir -Z query-dep-graph -Z threads=4
query stack during panic:
#0 [const_of_item] computing the type-level value for `EXAMPLE`
#1 [type_of] computing type of `BUF`
#2 [check_well_formed] checking that `BUF` 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 4 previous errors; 2 warnings emitted
Some errors have detailed explanations: E0425, E0601.
For more information about an error, try `rustc --explain E0425`.
@rustbot label +F-min_generic_const_args +-Zvalidate-mir
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-gca_min_const_items`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
matthiaskrgr commentedon Nov 9, 2025
kpreid commentedon Nov 13, 2025
None of the code samples posted so far ICE for me on
1.93.0-nightly (2025-11-12 01867557cd7dbe256a03)— they all produce other errors. However, completing the syntax of the last one makes it ICE again:Keith-Cancel commentedon Jan 5, 2026
I just encountered this error with some code like below. It was a little more complicated in my actually source since it was generated by a macro. However, enabling
min_generic_const_argsfor some experiments I want to try caused the ICE.https://godbolt.org/z/6vM5jesM9
rustc-ice-2026-01-05T21_03_41-27135.txt
reddevilmidzy commentedon Apr 13, 2026
fixed #152324
Since the syntax has been changed 152324, I don't think adding a test is necessary.