Skip to content

ICE: const variables should not be hashed #150409

@matthiaskrgr

Description

@matthiaskrgr

Code

#![allow(incomplete_features)]
#![feature(min_generic_const_args, adt_const_params)]

#[derive(Eq, PartialEq, core::marker::ConstParamTy)]
struct Foo;

trait Trait {
    #[type_const]
    const ASSOC: usize;
}

fn foo<const N: Foo>() {}

fn bar<T /*: Trait */, const N: u32>() {
    foo::<{ Some::<u32> { 0: <T as Trait>::ASSOC } }>();
}


fn main() {}

Meta

rustc --version --verbose:

rustc 1.94.0-nightly (82dd3cb00 2025-12-26)
binary: rustc
commit-hash: 82dd3cb008233bfe50ba6b8d6618e6bbd6054eb1
commit-date: 2025-12-26
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8

Error output

rustc --edition=2024 -Cincremental=. file.rs

error[E0277]: the trait bound `T: Trait` is not satisfied
  --> 43ED8FD6BE4A6E556F7BF056625A4B213D1844ED19E099262560C2BDA89BC4CD.rs:15:5
   |
15 |     foo::<{ Some::<u32> { 0: <T as Trait>::ASSOC } }>();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T`
   |
help: consider restricting type parameter `T` with trait `Trait`
   |
14 | fn bar<T: Trait /*: Trait */, const N: u32>() {
   |         +++++++

Backtrace

thread 'rustc' (2715443) panicked at /rustc-dev/82dd3cb008233bfe50ba6b8d6618e6bbd6054eb1/compiler/rustc_type_ir/src/const_kind.rs:124:17:
const variables should not be hashed: ?0c
stack backtrace:
   0:     0x7fc76285d173 - <<std[f001a44c88629918]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[ae8b9d0e4621198]::fmt::Display>::fmt
   1:     0x7fc763010648 - core[ae8b9d0e4621198]::fmt::write
   2:     0x7fc7628738c6 - <std[f001a44c88629918]::sys::stdio::unix::Stderr as std[f001a44c88629918]::io::Write>::write_fmt
   3:     0x7fc762833918 - std[f001a44c88629918]::panicking::default_hook::{closure#0}
   4:     0x7fc762850fe3 - std[f001a44c88629918]::panicking::default_hook
   5:     0x7fc76182c3da - std[f001a44c88629918]::panicking::update_hook::<alloc[911d02c9c88eb486]::boxed::Box<rustc_driver_impl[c839a11cb6d54e1f]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fc7628512c2 - std[f001a44c88629918]::panicking::panic_with_hook
   7:     0x7fc7628339d8 - std[f001a44c88629918]::panicking::panic_handler::{closure#0}
   8:     0x7fc76282aa79 - std[f001a44c88629918]::sys::backtrace::__rust_end_short_backtrace::<std[f001a44c88629918]::panicking::panic_handler::{closure#0}, !>
   9:     0x7fc7628354cd - __rustc[64332ed55f092eeb]::rust_begin_unwind
  10:     0x7fc75f3bcd1c - core[ae8b9d0e4621198]::panicking::panic_fmt
  11:     0x7fc7648db5ff - <rustc_type_ir[76a49b20610f69ea]::ty_info::WithCachedTypeInfo<rustc_type_ir[76a49b20610f69ea]::const_kind::ConstKind<rustc_middle[4d7782c0effc19af]::ty::context::TyCtxt>> as rustc_data_structures[dba0b2a223bbf7ac]::stable_hasher::HashStable<rustc_query_system[99e37e1c44f9e7af]::ich::hcx::StableHashingContext>>::hash_stable.cold
  12:     0x7fc762311d05 - <[rustc_middle[4d7782c0effc19af]::ty::consts::Const] as rustc_data_structures[dba0b2a223bbf7ac]::stable_hasher::HashStable<rustc_query_system[99e37e1c44f9e7af]::ich::hcx::StableHashingContext>>::hash_stable
  13:     0x7fc7648db552 - <rustc_type_ir[76a49b20610f69ea]::ty_info::WithCachedTypeInfo<rustc_type_ir[76a49b20610f69ea]::const_kind::ConstKind<rustc_middle[4d7782c0effc19af]::ty::context::TyCtxt>> as rustc_data_structures[dba0b2a223bbf7ac]::stable_hasher::HashStable<rustc_query_system[99e37e1c44f9e7af]::ich::hcx::StableHashingContext>>::hash_stable.cold
  14:     0x7fc76231b70e - <rustc_query_impl[45991da334863d29]::DynamicConfig<rustc_query_system[99e37e1c44f9e7af]::query::caches::DefaultCache<rustc_middle[4d7782c0effc19af]::ty::consts::Const, rustc_middle[4d7782c0effc19af]::query::erase::Erased<[u8; 24usize]>>, false, false, false> as rustc_query_system[99e37e1c44f9e7af]::query::config::QueryConfig<rustc_query_impl[45991da334863d29]::plumbing::QueryCtxt>>::construct_dep_node
  15:     0x7fc76225aa81 - rustc_query_system[99e37e1c44f9e7af]::query::plumbing::try_execute_query::<rustc_query_impl[45991da334863d29]::DynamicConfig<rustc_query_system[99e37e1c44f9e7af]::query::caches::DefaultCache<rustc_middle[4d7782c0effc19af]::ty::consts::Const, rustc_middle[4d7782c0effc19af]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[45991da334863d29]::plumbing::QueryCtxt, true>
  16:     0x7fc7622ce2f7 - rustc_query_impl[45991da334863d29]::query_impl::destructure_const::get_query_incr::__rust_end_short_backtrace
  17:     0x7fc761ecb432 - <rustc_middle[4d7782c0effc19af]::ty::print::pretty::FmtPrinter as rustc_middle[4d7782c0effc19af]::ty::print::pretty::PrettyPrinter>::pretty_print_const_valtree
  18:     0x7fc76262419f - <rustc_trait_selection[a5094546063c7f70]::error_reporting::TypeErrCtxt>::report_selection_error
  19:     0x7fc76116477a - <rustc_trait_selection[a5094546063c7f70]::error_reporting::TypeErrCtxt>::report_fulfillment_errors
  20:     0x7fc76348f366 - <rustc_hir_typeck[235f79563b033a8c]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  21:     0x7fc7634ab8ef - <rustc_hir_typeck[235f79563b033a8c]::fn_ctxt::FnCtxt>::check_expr_call
  22:     0x7fc76348c731 - <rustc_hir_typeck[235f79563b033a8c]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  23:     0x7fc76348787b - <rustc_hir_typeck[235f79563b033a8c]::fn_ctxt::FnCtxt>::check_expr_block
  24:     0x7fc76348c70c - <rustc_hir_typeck[235f79563b033a8c]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  25:     0x7fc76346d5cd - rustc_hir_typeck[235f79563b033a8c]::check::check_fn
  26:     0x7fc763ce6bb9 - rustc_hir_typeck[235f79563b033a8c]::typeck_with_inspect::{closure#0}
  27:     0x7fc763ce5530 - rustc_query_impl[45991da334863d29]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[45991da334863d29]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4d7782c0effc19af]::query::erase::Erased<[u8; 8usize]>>
  28:     0x7fc7632ceefe - rustc_query_system[99e37e1c44f9e7af]::query::plumbing::try_execute_query::<rustc_query_impl[45991da334863d29]::DynamicConfig<rustc_data_structures[dba0b2a223bbf7ac]::vec_cache::VecCache<rustc_span[e67fe8f95ccbc905]::def_id::LocalDefId, rustc_middle[4d7782c0effc19af]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[99e37e1c44f9e7af]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[45991da334863d29]::plumbing::QueryCtxt, true>
  29:     0x7fc7632ce303 - rustc_query_impl[45991da334863d29]::query_impl::typeck::get_query_incr::__rust_end_short_backtrace
  30:     0x7fc763813531 - <rustc_middle[4d7782c0effc19af]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[a4d216c74bb501db]::check_crate::{closure#2}>::{closure#0}
  31:     0x7fc763812f43 - rustc_hir_analysis[a4d216c74bb501db]::check_crate
  32:     0x7fc763f816db - rustc_interface[e352c8d967025ab4]::passes::analysis
  33:     0x7fc763f81335 - rustc_query_impl[45991da334863d29]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[45991da334863d29]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4d7782c0effc19af]::query::erase::Erased<[u8; 0usize]>>
  34:     0x7fc7643c340f - rustc_query_system[99e37e1c44f9e7af]::query::plumbing::try_execute_query::<rustc_query_impl[45991da334863d29]::DynamicConfig<rustc_query_system[99e37e1c44f9e7af]::query::caches::SingleCache<rustc_middle[4d7782c0effc19af]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[45991da334863d29]::plumbing::QueryCtxt, true>
  35:     0x7fc7643c2cbf - rustc_query_impl[45991da334863d29]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  36:     0x7fc7643cc191 - <rustc_interface[e352c8d967025ab4]::passes::create_and_enter_global_ctxt<core[ae8b9d0e4621198]::option::Option<rustc_interface[e352c8d967025ab4]::queries::Linker>, rustc_driver_impl[c839a11cb6d54e1f]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[ae8b9d0e4621198]::ops::function::FnOnce<(&rustc_session[8540b73cd1ac76e8]::session::Session, rustc_middle[4d7782c0effc19af]::ty::context::CurrentGcx, alloc[911d02c9c88eb486]::sync::Arc<rustc_data_structures[dba0b2a223bbf7ac]::jobserver::Proxy>, &std[f001a44c88629918]::sync::once_lock::OnceLock<rustc_middle[4d7782c0effc19af]::ty::context::GlobalCtxt>, &rustc_data_structures[dba0b2a223bbf7ac]::sync::worker_local::WorkerLocal<rustc_middle[4d7782c0effc19af]::arena::Arena>, &rustc_data_structures[dba0b2a223bbf7ac]::sync::worker_local::WorkerLocal<rustc_hir[6f4bc43c8951dbe0]::Arena>, rustc_driver_impl[c839a11cb6d54e1f]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  37:     0x7fc76423ea0a - rustc_interface[e352c8d967025ab4]::interface::run_compiler::<(), rustc_driver_impl[c839a11cb6d54e1f]::run_compiler::{closure#0}>::{closure#1}
  38:     0x7fc7641c82ce - std[f001a44c88629918]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[e352c8d967025ab4]::util::run_in_thread_with_globals<rustc_interface[e352c8d967025ab4]::util::run_in_thread_pool_with_globals<rustc_interface[e352c8d967025ab4]::interface::run_compiler<(), rustc_driver_impl[c839a11cb6d54e1f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  39:     0x7fc7641c80a0 - <std[f001a44c88629918]::thread::lifecycle::spawn_unchecked<rustc_interface[e352c8d967025ab4]::util::run_in_thread_with_globals<rustc_interface[e352c8d967025ab4]::util::run_in_thread_pool_with_globals<rustc_interface[e352c8d967025ab4]::interface::run_compiler<(), rustc_driver_impl[c839a11cb6d54e1f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[ae8b9d0e4621198]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  40:     0x7fc7641c6478 - <std[f001a44c88629918]::sys::thread::unix::Thread>::new::thread_start
  41:     0x7fc75d89698b - <unknown>
  42:     0x7fc75d91a9cc - <unknown>
  43:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

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: please attach the file at `/tmp/im5/rustc-ice-2025-12-26T21_34_25-2715441.txt` to your bug report

note: rustc 1.94.0-nightly (82dd3cb00 2025-12-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -C incremental=[REDACTED]

query stack during panic:
panicked at /rustc-dev/82dd3cb008233bfe50ba6b8d6618e6bbd6054eb1/compiler/rustc_type_ir/src/const_kind.rs:124:17:

thread panicked while processing panic. aborting.

Metadata

Metadata

Labels

A-incr-compArea: Incremental compilationC-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-adt_const_params`#![feature(adt_const_params)]`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