rust-lang / rust-lang/rust

[ICE]: `can't type-check body of DefId` mgca + supertrait_item_shadowing (none-gce repro)

Open
#159,169 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-min_generic_const_args F-supertrait_item_shadowing I-ICE needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

auto-reduced (treereduce-rust):

#![feature(min_generic_const_args)]
#![feature(supertrait_item_shadowing)]
trait A {
    type Assoc;
    const CONST: i32;
}
impl<T> A for T {
    type Assoc = i8;
    const CONST: i32 = 1;
}
trait B: A {
    type Assoc;
    const CONST: i32;
}
impl<T> B for T {
    type Assoc = i16;
    type const CONST: i32 = 2;
}

fn konst<T>() -> i32 {
    T::CONST
}
fn main() {
    assert_eq!(konst::<()>(), 2)
}

original:

#![feature(min_generic_const_args)]
#![feature(supertrait_item_shadowing)]
trait A {
    fn hello() -> &'static str {
        "A"
    }
    type Assoc;
    const CONST: i32;
}
impl<T> A for T {
    type Assoc = i8;
    const CONST: i32 = 1;
}
trait B: A {
    fn hello() -> &'static str {
        ""
    }
    type Assoc;
    const CONST: i32;
}
impl<T> B for T {
    type Assoc = i16;
    type const CONST: i32 = 2;
}
fn foo<T>() -> &'static str {
    T::hello()
}
fn assoc<T>() -> usize {
    size_of::<T>()
}
fn konst<T>() -> i32 {
    T::CONST
}
fn main() {
    assert_eq!(konst::<()>(), 2)
}

Version information

rustc 1.99.0-nightly (be8e82435 2026-07-11)
binary: rustc
commit-hash: be8e82435eb04fbe75ed5286b52735366e160bed
commit-date: 2026-07-11
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 22.1.8

Possibly related line of code:
https://github.com/rust-lang/rust/blob/be8e82435eb04fbe75ed5286b52735366e160bed/compiler/rustc_hir_typeck/src/lib.rs#L118-L130

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

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.fXNCZ5e1FnPE/rustc_testrunner_tmpdir_reporting.rc99AX6NMEnG/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: associated constant `CONST` is never used
 --> /tmp/icemaker_global_tempdir.fXNCZ5e1FnPE/rustc_testrunner_tmpdir_reporting.rc99AX6NMEnG/mvce.rs:5:11
  |
3 | trait A {
  |       - associated constant in this trait
4 |     type Assoc;
5 |     const CONST: i32;
  |           ^^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

error: internal compiler error: /rustc-dev/be8e82435eb04fbe75ed5286b52735366e160bed/compiler/rustc_hir_typeck/src/lib.rs:124:9: can't type-check body of DefId(0:16 ~ mvce[7724]::{impl#1}::CONST)
  --> /tmp/icemaker_global_tempdir.fXNCZ5e1FnPE/rustc_testrunner_tmpdir_reporting.rc99AX6NMEnG/mvce.rs:17:5
   |
17 |     type const CONST: i32 = 2;
   |     ^^^^^^^^^^^^^^^^^^^^^


thread 'rustc' (3709140) panicked at /rustc-dev/be8e82435eb04fbe75ed5286b52735366e160bed/compiler/rustc_hir_typeck/src/lib.rs:124:9:
Box<dyn Any>
stack backtrace:
   0:     0x7f9de2fef336 - <<std[9dee65175fc15e8a]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[f7c17f95b9e87ecb]::fmt::Display>::fmt
   1:     0x7f9de360f0c8 - core[f7c17f95b9e87ecb]::fmt::write
   2:     0x7f9de30047ac - <std[9dee65175fc15e8a]::sys::stdio::unix::Stderr as core[f7c17f95b9e87ecb]::io::write::Write>::write_fmt
   3:     0x7f9de2fc36ba - std[9dee65175fc15e8a]::panicking::default_hook::{closure#0}
   4:     0x7f9de2fe1a53 - std[9dee65175fc15e8a]::panicking::default_hook
   5:     0x7f9de1fbbe2b - std[9dee65175fc15e8a]::panicking::update_hook::<alloc[6f37f170616d1c17]::boxed::Box<rustc_driver_impl[bdac25697827ee93]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f9de2fe1ef2 - std[9dee65175fc15e8a]::panicking::panic_with_hook
   7:     0x7f9de1fe8e71 - std[9dee65175fc15e8a]::panicking::begin_panic::<rustc_errors[494ff315151c0f38]::ExplicitBug>::{closure#0}
   8:     0x7f9de1fe1e66 - std[9dee65175fc15e8a]::sys::backtrace::__rust_end_short_backtrace::<std[9dee65175fc15e8a]::panicking::begin_panic<rustc_errors[494ff315151c0f38]::ExplicitBug>::{closure#0}, !>
   9:     0x7f9de1fdfc27 - std[9dee65175fc15e8a]::panicking::begin_panic::<rustc_errors[494ff315151c0f38]::ExplicitBug>
  10:     0x7f9de1ff4001 - <rustc_errors[494ff315151c0f38]::diagnostic::BugAbort as rustc_errors[494ff315151c0f38]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f9de254a3bc - <rustc_errors[494ff315151c0f38]::DiagCtxtHandle>::span_bug::<rustc_span[fa652b6c2772fbf8]::span_encoding::Span, alloc[6f37f170616d1c17]::string::String>
  12:     0x7f9de2579546 - rustc_middle[dc20d7af34d4b5d8]::util::bug::opt_span_bug_fmt::<rustc_span[fa652b6c2772fbf8]::span_encoding::Span>::{closure#0}
  13:     0x7f9de25796d2 - rustc_middle[dc20d7af34d4b5d8]::ty::context::tls::with_opt::<rustc_middle[dc20d7af34d4b5d8]::util::bug::opt_span_bug_fmt<rustc_span[fa652b6c2772fbf8]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7f9de2564eab - rustc_middle[dc20d7af34d4b5d8]::ty::context::tls::with_context_opt::<rustc_middle[dc20d7af34d4b5d8]::ty::context::tls::with_opt<rustc_middle[dc20d7af34d4b5d8]::util::bug::opt_span_bug_fmt<rustc_span[fa652b6c2772fbf8]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7f9de05f7a98 - rustc_middle[dc20d7af34d4b5d8]::util::bug::span_bug_fmt::<rustc_span[fa652b6c2772fbf8]::span_encoding::Span>
  16:     0x7f9de0f1b08a - rustc_hir_typeck[7fefe0441a069e2b]::typeck_with_inspect::{closure#0}::{closure#0}
  17:     0x7f9de47dead7 - rustc_hir_typeck[7fefe0441a069e2b]::typeck_with_inspect::{closure#0}
  18:     0x7f9de47d72b0 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
  19:     0x7f9de3c51aa9 - rustc_query_impl[65ec22dc7d75fb0e]::execution::try_execute_query::<rustc_data_structures[7274291927d51f67]::vec_cache::VecCache<rustc_span[fa652b6c2772fbf8]::def_id::LocalDefId, rustc_middle[dc20d7af34d4b5d8]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[dc20d7af34d4b5d8]::dep_graph::graph::DepNodeIndex>, false>
  20:     0x7f9de3c51503 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
  21:     0x7f9de3c58e5d - rustc_mir_build[eeeb229b717c14b9]::thir::pattern::check_match::check_match
  22:     0x7f9de3c57f87 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::check_match::invoke_provider_fn::__rust_begin_short_backtrace
  23:     0x7f9de43cc313 - rustc_query_impl[65ec22dc7d75fb0e]::execution::try_execute_query::<rustc_data_structures[7274291927d51f67]::vec_cache::VecCache<rustc_span[fa652b6c2772fbf8]::def_id::LocalDefId, rustc_middle[dc20d7af34d4b5d8]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[dc20d7af34d4b5d8]::dep_graph::graph::DepNodeIndex>, false>
  24:     0x7f9de43cbf76 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::check_match::execute_query_non_incr::__rust_end_short_backtrace
  25:     0x7f9de3e53893 - rustc_mir_build[eeeb229b717c14b9]::builder::build_mir_inner_impl
  26:     0x7f9de360feaa - rustc_mir_transform[4c85edcd2f644699]::mir_built
  27:     0x7f9de3c51aa9 - rustc_query_impl[65ec22dc7d75fb0e]::execution::try_execute_query::<rustc_data_structures[7274291927d51f67]::vec_cache::VecCache<rustc_span[fa652b6c2772fbf8]::def_id::LocalDefId, rustc_middle[dc20d7af34d4b5d8]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[dc20d7af34d4b5d8]::dep_graph::graph::DepNodeIndex>, false>
  28:     0x7f9de3c51743 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::mir_built::execute_query_non_incr::__rust_end_short_backtrace
  29:     0x7f9de37921e8 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::trivial_const::invoke_provider_fn::__rust_begin_short_backtrace
  30:     0x7f9de378f0b6 - rustc_query_impl[65ec22dc7d75fb0e]::execution::try_execute_query::<rustc_middle[dc20d7af34d4b5d8]::query::caches::DefIdCache<rustc_middle[dc20d7af34d4b5d8]::query::erase::ErasedData<[u8; 32usize]>>, false>
  31:     0x7f9de378e71e - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::trivial_const::execute_query_non_incr::__rust_end_short_backtrace
  32:     0x7f9de4140ed8 - rustc_const_eval[5c4fc539338c4d99]::const_eval::eval_queries::eval_to_const_value_raw_provider
  33:     0x7f9de41403d6 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::eval_to_const_value_raw::invoke_provider_fn::__rust_begin_short_backtrace
  34:     0x7f9de413f1f0 - rustc_query_impl[65ec22dc7d75fb0e]::execution::try_execute_query::<rustc_middle[dc20d7af34d4b5d8]::query::caches::DefaultCache<rustc_middle[dc20d7af34d4b5d8]::ty::PseudoCanonicalInput<rustc_middle[dc20d7af34d4b5d8]::mir::interpret::GlobalId>, rustc_middle[dc20d7af34d4b5d8]::query::erase::ErasedData<[u8; 24usize]>>, false>
  35:     0x7f9de413edcb - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::eval_to_const_value_raw::execute_query_non_incr::__rust_end_short_backtrace
  36:     0x7f9de4185db1 - <rustc_middle[dc20d7af34d4b5d8]::ty::context::TyCtxt>::const_eval_resolve
  37:     0x7f9de418f537 - rustc_monomorphize[5ddff886982a32e]::collector::items_of_instance
  38:     0x7f9de418e491 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::items_of_instance::invoke_provider_fn::__rust_begin_short_backtrace
  39:     0x7f9de41a5d98 - rustc_query_impl[65ec22dc7d75fb0e]::execution::try_execute_query::<rustc_middle[dc20d7af34d4b5d8]::query::caches::DefaultCache<(rustc_middle[dc20d7af34d4b5d8]::ty::instance::Instance, rustc_middle[dc20d7af34d4b5d8]::mono::CollectionMode), rustc_middle[dc20d7af34d4b5d8]::query::erase::ErasedData<[u8; 32usize]>>, false>
  40:     0x7f9de41a5a03 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::items_of_instance::execute_query_non_incr::__rust_end_short_backtrace
  41:     0x7f9de41a4794 - rustc_monomorphize[5ddff886982a32e]::collector::collect_items_rec::{closure#0}
  42:     0x7f9de4a5ac40 - rustc_monomorphize[5ddff886982a32e]::collector::collect_items_rec
  43:     0x7f9de4a5c5cb - rustc_monomorphize[5ddff886982a32e]::collector::collect_items_rec
  44:     0x7f9de3e03061 - rustc_monomorphize[5ddff886982a32e]::collector::collect_crate_mono_items::{closure#1}::{closure#0}
  45:     0x7f9de420fdf5 - rustc_monomorphize[5ddff886982a32e]::partitioning::collect_and_partition_mono_items
  46:     0x7f9de476f228 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::collect_and_partition_mono_items::invoke_provider_fn::__rust_begin_short_backtrace
  47:     0x7f9de476eb81 - rustc_query_impl[65ec22dc7d75fb0e]::execution::try_execute_query::<rustc_middle[dc20d7af34d4b5d8]::query::caches::SingleCache<rustc_middle[dc20d7af34d4b5d8]::query::erase::ErasedData<[u8; 24usize]>>, false>
  48:     0x7f9de476e83c - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::collect_and_partition_mono_items::execute_query_non_incr::__rust_end_short_backtrace
  49:     0x7f9de492544c - rustc_codegen_ssa[6bd443ac0c28161e]::base::codegen_crate::<rustc_codegen_llvm[e8ec844b0182af14]::LlvmCodegenBackend, rustc_codegen_llvm[e8ec844b0182af14]::ModuleLlvm>
  50:     0x7f9de492514d - <rustc_codegen_llvm[e8ec844b0182af14]::LlvmCodegenBackend as rustc_codegen_ssa[6bd443ac0c28161e]::traits::backend::CodegenBackend>::codegen_crate
  51:     0x7f9de470c561 - <rustc_interface[3c71d144d463ca91]::queries::Linker>::codegen_and_build_linker
  52:     0x7f9de4707b5c - rustc_interface[3c71d144d463ca91]::interface::run_compiler::<(), rustc_driver_impl[bdac25697827ee93]::run_compiler::{closure#0}>::{closure#1}
  53:     0x7f9de475b57a - std[9dee65175fc15e8a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[3c71d144d463ca91]::util::run_in_thread_with_globals<rustc_interface[3c71d144d463ca91]::util::run_in_thread_pool_with_globals<rustc_interface[3c71d144d463ca91]::interface::run_compiler<(), rustc_driver_impl[bdac25697827ee93]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  54:     0x7f9de475b32d - <std[9dee65175fc15e8a]::thread::lifecycle::spawn_unchecked<rustc_interface[3c71d144d463ca91]::util::run_in_thread_with_globals<rustc_interface[3c71d144d463ca91]::util::run_in_thread_pool_with_globals<rustc_interface[3c71d144d463ca91]::interface::run_compiler<(), rustc_driver_impl[bdac25697827ee93]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[f7c17f95b9e87ecb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  55:     0x7f9de475f750 - <std[9dee65175fc15e8a]::sys::thread::unix::Thread>::new::thread_start
  56:     0x7f9dde097739 - <unknown>
  57:     0x7f9dde11bedc - <unknown>
  58:                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.99.0-nightly (be8e82435 2026-07-11) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck_root] type-checking `<impl at /tmp/icemaker_global_tempdir.fXNCZ5e1FnPE/rustc_testrunner_tmpdir_reporting.rc99AX6NMEnG/mvce.rs:15:1: 15:16>::CONST`
#1 [check_match] match-checking `<impl at /tmp/icemaker_global_tempdir.fXNCZ5e1FnPE/rustc_testrunner_tmpdir_reporting.rc99AX6NMEnG/mvce.rs:15:1: 15:16>::CONST`
#2 [mir_built] building MIR for `<impl at /tmp/icemaker_global_tempdir.fXNCZ5e1FnPE/rustc_testrunner_tmpdir_reporting.rc99AX6NMEnG/mvce.rs:15:1: 15:16>::CONST`
#3 [trivial_const] checking if `<impl at /tmp/icemaker_global_tempdir.fXNCZ5e1FnPE/rustc_testrunner_tmpdir_reporting.rc99AX6NMEnG/mvce.rs:15:1: 15:16>::CONST` is a trivial const
#4 [eval_to_const_value_raw] simplifying constant for the type system `<impl at /tmp/icemaker_global_tempdir.fXNCZ5e1FnPE/rustc_testrunner_tmpdir_reporting.rc99AX6NMEnG/mvce.rs:15:1: 15:16>::CONST`
#5 [items_of_instance] collecting items used by `konst::<()>`
#6 [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 +F-supertrait_item_shadowing

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the ICE with the reduced a.rs example using the nightly rustc command. Start at compiler/rustc_hir_typeck/src/lib.rs lines 118-130 and trace the type-checking path for the impl constant; done means this input no longer triggers an internal compiler error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.