Skip to content

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

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

trait BadTr { } impl BadTr for GoodS { #[type_const] const NUM: = 84; }

original:

#![expect(incomplete_features)] #![feature(associated_const_equality, min_generic_const_args)] trait BadTr { const NUM: usize; } struct GoodS; impl BadTr for GoodS { #[type_const] const NUM: = 84; } fn accept_bad_tr<const N: usize, T: BadTr<NUM = { N }>>(_x: &T) {} //~^ ERROR use of trait associated const without `#[type_const]` fn main() { accept_bad_tr::<GoodS = { N }>(&GoodS); }

Version information

rustc 1.93.0-nightly (acda5e9f9 2025-11-09) binary: rustc commit-hash: acda5e9f9aadac705b851935b14aa3d34a67d428 commit-date: 2025-11-09 host: x86_64-unknown-linux-gnu release: 1.93.0-nightly LLVM version: 21.1.3 

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

Program output

error[E0438]: const `NUM` is not a member of trait `BadTr` --> /tmp/icemaker_global_tempdir.pcYJpEqsAGEB/rustc_testrunner_tmpdir_reporting.d7A4ynwfWceP/mvce.rs:12:5 | 12 | const NUM: = 84; | ^^^^^^^^^^^^^^^^^ not a member of trait `BadTr` error[E0412]: cannot find type `GoodS` in this scope --> /tmp/icemaker_global_tempdir.pcYJpEqsAGEB/rustc_testrunner_tmpdir_reporting.d7A4ynwfWceP/mvce.rs:10:16 | 10 | impl BadTr for GoodS { | ^^^^^ not found in this scope error[E0658]: the `#[type_const]` attribute is an experimental feature --> /tmp/icemaker_global_tempdir.pcYJpEqsAGEB/rustc_testrunner_tmpdir_reporting.d7A4ynwfWceP/mvce.rs:11:5 | 11 | #[type_const] | ^^^^^^^^^^^^^ | = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on 2025-11-09; consider upgrading it if it is out of date error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.pcYJpEqsAGEB/rustc_testrunner_tmpdir_reporting.d7A4ynwfWceP/mvce.rs:13:2 | 13 | } | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.pcYJpEqsAGEB/rustc_testrunner_tmpdir_reporting.d7A4ynwfWceP/mvce.rs` error: internal compiler error: compiler/rustc_hir_typeck/src/lib.rs:127:9: can't type-check body of DefId(0:5 ~ mvce[3608]::{impl#0}::NUM) --> /tmp/icemaker_global_tempdir.pcYJpEqsAGEB/rustc_testrunner_tmpdir_reporting.d7A4ynwfWceP/mvce.rs:12:5 | 12 | const NUM: = 84; | ^^^^^^^^^^ thread 'rustc' (3860575) panicked at compiler/rustc_hir_typeck/src/lib.rs:127:9: Box<dyn Any> stack backtrace: 0: 0x7f2b3026c9c3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h0dc93c2810c40bd0 1: 0x7f2b30a01afc - core::fmt::write::hacdaf2bbd154e9b5 2: 0x7f2b30221533 - std::io::Write::write_fmt::h75e948926e9dfbe3 3: 0x7f2b30232b42 - std::sys::backtrace::BacktraceLock::print::h251013828edeee18 4: 0x7f2b30238b99 - std::panicking::default_hook::{{closure}}::hf6c9462acd913055 5: 0x7f2b302386c3 - std::panicking::default_hook::h4c9fd5029d2f8b73 6: 0x7f2b2f22a721 - std[b4c06921f787550c]::panicking::update_hook::<alloc[7ed4a9fe7ec582b8]::boxed::Box<rustc_driver_impl[87c4f5c8377f9862]::install_ice_hook::{closure#1}>>::{closure#0} 7: 0x7f2b30238fbf - std::panicking::panic_with_hook::h02a757165762df79 8: 0x7f2b2f266cb1 - std[b4c06921f787550c]::panicking::begin_panic::<rustc_errors[373a255116eccc4c]::ExplicitBug>::{closure#0} 9: 0x7f2b2f2593d6 - std[b4c06921f787550c]::sys::backtrace::__rust_end_short_backtrace::<std[b4c06921f787550c]::panicking::begin_panic<rustc_errors[373a255116eccc4c]::ExplicitBug>::{closure#0}, !> 10: 0x7f2b2f256a94 - std[b4c06921f787550c]::panicking::begin_panic::<rustc_errors[373a255116eccc4c]::ExplicitBug> 11: 0x7f2b2f285321 - <rustc_errors[373a255116eccc4c]::diagnostic::BugAbort as rustc_errors[373a255116eccc4c]::diagnostic::EmissionGuarantee>::emit_producing_guarantee 12: 0x7f2b2f7ea57c - <rustc_errors[373a255116eccc4c]::DiagCtxtHandle>::span_bug::<rustc_span[39972e28049286de]::span_encoding::Span, alloc[7ed4a9fe7ec582b8]::string::String> 13: 0x7f2b2f80da87 - rustc_middle[1e1513fa521466b3]::util::bug::opt_span_bug_fmt::<rustc_span[39972e28049286de]::span_encoding::Span>::{closure#0} 14: 0x7f2b2f80dc2a - rustc_middle[1e1513fa521466b3]::ty::context::tls::with_opt::<rustc_middle[1e1513fa521466b3]::util::bug::opt_span_bug_fmt<rustc_span[39972e28049286de]::span_encoding::Span>::{closure#0}, !>::{closure#0} 15: 0x7f2b2f7fe63b - rustc_middle[1e1513fa521466b3]::ty::context::tls::with_context_opt::<rustc_middle[1e1513fa521466b3]::ty::context::tls::with_opt<rustc_middle[1e1513fa521466b3]::util::bug::opt_span_bug_fmt<rustc_span[39972e28049286de]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !> 16: 0x7f2b2db06757 - rustc_middle[1e1513fa521466b3]::util::bug::span_bug_fmt::<rustc_span[39972e28049286de]::span_encoding::Span> 17: 0x7f2b31bd6e1a - rustc_hir_typeck[b7947f0b53f42892]::typeck_with_inspect::{closure#0} 18: 0x7f2b31bcf00e - rustc_query_impl[d4db0883806fa552]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d4db0883806fa552]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1e1513fa521466b3]::query::erase::Erased<[u8; 8usize]>> 19: 0x7f2b30c53677 - rustc_query_system[d03d33f2f2d15895]::query::plumbing::try_execute_query::<rustc_query_impl[d4db0883806fa552]::DynamicConfig<rustc_data_structures[aff1d8a073485c2a]::vec_cache::VecCache<rustc_span[39972e28049286de]::def_id::LocalDefId, rustc_middle[1e1513fa521466b3]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[d03d33f2f2d15895]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[d4db0883806fa552]::plumbing::QueryCtxt, false> 20: 0x7f2b30c53009 - rustc_query_impl[d4db0883806fa552]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace 21: 0x7f2b2f3f11c9 - rustc_hir_analysis[3bbcf63e422e422d]::collect::type_of::infer_placeholder_type 22: 0x7f2b313f127e - rustc_hir_analysis[3bbcf63e422e422d]::collect::type_of::type_of 23: 0x7f2b30a1d926 - rustc_query_impl[d4db0883806fa552]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d4db0883806fa552]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1e1513fa521466b3]::query::erase::Erased<[u8; 8usize]>> 24: 0x7f2b30a1c5c6 - rustc_query_system[d03d33f2f2d15895]::query::plumbing::try_execute_query::<rustc_query_impl[d4db0883806fa552]::DynamicConfig<rustc_query_system[d03d33f2f2d15895]::query::caches::DefIdCache<rustc_middle[1e1513fa521466b3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d4db0883806fa552]::plumbing::QueryCtxt, false> 25: 0x7f2b30a1c16f - rustc_query_impl[d4db0883806fa552]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace 26: 0x7f2b3120ddd9 - rustc_hir_analysis[3bbcf63e422e422d]::check::check::check_item_type 27: 0x7f2b3120c41c - rustc_hir_analysis[3bbcf63e422e422d]::check::wfcheck::check_well_formed 28: 0x7f2b3120c3f5 - rustc_query_impl[d4db0883806fa552]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d4db0883806fa552]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1e1513fa521466b3]::query::erase::Erased<[u8; 1usize]>> 29: 0x7f2b3120bc6c - rustc_query_system[d03d33f2f2d15895]::query::plumbing::try_execute_query::<rustc_query_impl[d4db0883806fa552]::DynamicConfig<rustc_data_structures[aff1d8a073485c2a]::vec_cache::VecCache<rustc_span[39972e28049286de]::def_id::LocalDefId, rustc_middle[1e1513fa521466b3]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[d03d33f2f2d15895]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[d4db0883806fa552]::plumbing::QueryCtxt, false> 30: 0x7f2b3120b782 - rustc_query_impl[d4db0883806fa552]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace 31: 0x7f2b31208d08 - rustc_hir_analysis[3bbcf63e422e422d]::check::wfcheck::check_type_wf 32: 0x7f2b31208bf9 - rustc_query_impl[d4db0883806fa552]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d4db0883806fa552]::query_impl::check_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1e1513fa521466b3]::query::erase::Erased<[u8; 1usize]>> 33: 0x7f2b31a47dd4 - rustc_query_system[d03d33f2f2d15895]::query::plumbing::try_execute_query::<rustc_query_impl[d4db0883806fa552]::DynamicConfig<rustc_query_system[d03d33f2f2d15895]::query::caches::SingleCache<rustc_middle[1e1513fa521466b3]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[d4db0883806fa552]::plumbing::QueryCtxt, false> 34: 0x7f2b31a47bb6 - rustc_query_impl[d4db0883806fa552]::query_impl::check_type_wf::get_query_non_incr::__rust_end_short_backtrace 35: 0x7f2b3152ea3a - rustc_hir_analysis[3bbcf63e422e422d]::check_crate 36: 0x7f2b30c497b0 - rustc_interface[df9ddd9c9467ef8b]::passes::analysis 37: 0x7f2b30c49465 - rustc_query_impl[d4db0883806fa552]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d4db0883806fa552]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1e1513fa521466b3]::query::erase::Erased<[u8; 0usize]>> 38: 0x7f2b31a4e814 - rustc_query_system[d03d33f2f2d15895]::query::plumbing::try_execute_query::<rustc_query_impl[d4db0883806fa552]::DynamicConfig<rustc_query_system[d03d33f2f2d15895]::query::caches::SingleCache<rustc_middle[1e1513fa521466b3]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[d4db0883806fa552]::plumbing::QueryCtxt, false> 39: 0x7f2b31a4e44a - rustc_query_impl[d4db0883806fa552]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 40: 0x7f2b31d09f83 - <rustc_interface[df9ddd9c9467ef8b]::passes::create_and_enter_global_ctxt<core[f1f7c8de62d6692e]::option::Option<rustc_interface[df9ddd9c9467ef8b]::queries::Linker>, rustc_driver_impl[87c4f5c8377f9862]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[f1f7c8de62d6692e]::ops::function::FnOnce<(&rustc_session[5dff62ba5cbc554d]::session::Session, rustc_middle[1e1513fa521466b3]::ty::context::CurrentGcx, alloc[7ed4a9fe7ec582b8]::sync::Arc<rustc_data_structures[aff1d8a073485c2a]::jobserver::Proxy>, &std[b4c06921f787550c]::sync::once_lock::OnceLock<rustc_middle[1e1513fa521466b3]::ty::context::GlobalCtxt>, &rustc_data_structures[aff1d8a073485c2a]::sync::worker_local::WorkerLocal<rustc_middle[1e1513fa521466b3]::arena::Arena>, &rustc_data_structures[aff1d8a073485c2a]::sync::worker_local::WorkerLocal<rustc_hir[2565f01ea710f611]::Arena>, rustc_driver_impl[87c4f5c8377f9862]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0} 41: 0x7f2b31b8ec69 - rustc_interface[df9ddd9c9467ef8b]::interface::run_compiler::<(), rustc_driver_impl[87c4f5c8377f9862]::run_compiler::{closure#0}>::{closure#1} 42: 0x7f2b3188c98f - std[b4c06921f787550c]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[df9ddd9c9467ef8b]::util::run_in_thread_with_globals<rustc_interface[df9ddd9c9467ef8b]::util::run_in_thread_pool_with_globals<rustc_interface[df9ddd9c9467ef8b]::interface::run_compiler<(), rustc_driver_impl[87c4f5c8377f9862]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()> 43: 0x7f2b3188c670 - <<std[b4c06921f787550c]::thread::Builder>::spawn_unchecked_<rustc_interface[df9ddd9c9467ef8b]::util::run_in_thread_with_globals<rustc_interface[df9ddd9c9467ef8b]::util::run_in_thread_pool_with_globals<rustc_interface[df9ddd9c9467ef8b]::interface::run_compiler<(), rustc_driver_impl[87c4f5c8377f9862]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[f1f7c8de62d6692e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 44: 0x7f2b3188afef - std::sys::thread::unix::Thread::new::thread_start::h6ee5f4a2e2de181d 45: 0x7f2b2b2969cb - <unknown> 46: 0x7f2b2b31aa0c - <unknown> 47: 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 (acda5e9f9 2025-11-09) running on x86_64-unknown-linux-gnu query stack during panic: #0 [typeck] type-checking `<impl at /tmp/icemaker_global_tempdir.pcYJpEqsAGEB/rustc_testrunner_tmpdir_reporting.d7A4ynwfWceP/mvce.rs:10:1: 10:21>::NUM` #1 [type_of] computing type of `<impl at /tmp/icemaker_global_tempdir.pcYJpEqsAGEB/rustc_testrunner_tmpdir_reporting.d7A4ynwfWceP/mvce.rs:10:1: 10:21>::NUM` #2 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.pcYJpEqsAGEB/rustc_testrunner_tmpdir_reporting.d7A4ynwfWceP/mvce.rs:10:1: 10:21>::NUM` 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: missing type for `const` item --> /tmp/icemaker_global_tempdir.pcYJpEqsAGEB/rustc_testrunner_tmpdir_reporting.d7A4ynwfWceP/mvce.rs:12:15 | 12 | const NUM: = 84; | ^ | help: provide a type for the item | 12 | const NUM: <type> = 84; | ++++++ error: aborting due to 6 previous errors Some errors have detailed explanations: E0412, E0438, E0601, E0658. For more information about an error, try `rustc --explain E0412`. 

@rustbot label +F-associated_const_equality +F-min_generic_const_args

Metadata

Metadata

Assignees

No one assigned

    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