rust-lang / rust-lang/rust

[ICE]: `cannot call const_of_item on a non-type_const`

Open
#161,523 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

snippet:

#![feature(min_generic_const_args)]
#![feature(macroless_generic_const_args)]
#![feature(generic_const_args)]
#![feature(generic_const_exprs)]

trait MyTrait {
    type ArrayType;
    const SIZE: usize;
    const ARRAY: Self::ArrayType;
}
impl MyTrait for () {
    type ArrayType = [u8; Self::SIZE];
    const SIZE: usize = 4;
    const ARRAY: [u8; Self::SIZE] = [1, 2, 3, 4];
}

fn main() {}

Version information

rustc 1.100.0-nightly (def3ee9e4 2026-08-22)
binary: rustc
commit-hash: def3ee9e4f0fe1429574f402bb624439bbd13fc6
commit-date: 2026-08-22
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.0

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

Program output

warning: `feature(generic_const_exprs)` is not supported with the next-generation trait solver
 --> /tmp/icemaker_global_tempdir.LHp6rrJaEQyb/rustc_testrunner_tmpdir_reporting.XILLXqwBzPqr/mvce.rs:4:12
  |
4 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: `-Znext-solver=globally` is currently enabled by default for testing
  = note: reverted the setting to `-Znext-solver=coherence` for this crate
  = note: the currently stable trait solver will be used for this crate
  = note: see issues #160895 <https://github.com/rust-lang/rust/issues/160895> for more information

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

warning: the feature `generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.LHp6rrJaEQyb/rustc_testrunner_tmpdir_reporting.XILLXqwBzPqr/mvce.rs:3:12
  |
3 | #![feature(generic_const_args)]
  |            ^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #151972 <https://github.com/rust-lang/rust/issues/151972> for more information

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

warning: trait `MyTrait` is never used
 --> /tmp/icemaker_global_tempdir.LHp6rrJaEQyb/rustc_testrunner_tmpdir_reporting.XILLXqwBzPqr/mvce.rs:6:7
  |
6 | trait MyTrait {
  |       ^^^^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: 6 warnings emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: cannot call const_of_item on a non-type_const
  --> /tmp/icemaker_global_tempdir.LHp6rrJaEQyb/rustc_testrunner_tmpdir_reporting.XILLXqwBzPqr/mvce.rs:13:5
   |
13 |     const SIZE: usize = 4;
   |     ^^^^^^^^^^^^^^^^^
   |
note: delayed at /rustc-dev/def3ee9e4f0fe1429574f402bb624439bbd13fc6/compiler/rustc_hir_analysis/src/collect.rs:1693:31
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         4: rustc_hir_analysis::collect::const_of_item
         5: rustc_query_impl::query_vtables::const_of_item::invoke_provider_fn::__rust_begin_short_backtrace
         6: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefIdCache<rustc_middle::query::erase::ErasedData<[u8; 8]>>, false>
         7: rustc_query_impl::query_vtables::const_of_item::execute_query_non_incr::__rust_end_short_backtrace
         8: rustc_trait_selection::traits::project::confirm_candidate
         9: rustc_trait_selection::traits::project::normalize_projection_term
        10: rustc_traits::normalize_projection_ty::normalize_canonicalized_projection
        11: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefaultCache<rustc_type_ir::canonical::CanonicalQueryInput<rustc_middle::ty::context::TyCtxt, rustc_middle::ty::ParamEnvAnd<rustc_type_ir::ty::alias::Alias<rustc_middle::ty::context::TyCtxt, rustc_type_ir::term_kind::AliasTermKind<rustc_middle::ty::context::TyCtxt>>>>, rustc_middle::query::erase::ErasedData<[u8; 8]>>, false>
        12: rustc_query_impl::query_vtables::normalize_canonicalized_projection::execute_query_non_incr::__rust_end_short_backtrace
        13: <rustc_trait_selection::traits::query::normalize::QueryNormalizer>::try_fold_free_or_assoc
        14: <rustc_trait_selection::traits::query::normalize::QueryNormalizer as rustc_type_ir::fold::FallibleTypeFolder<rustc_middle::ty::context::TyCtxt>>::try_fold_const
        15: <rustc_traits::normalize_erasing_regions::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_middle::ty::PseudoCanonicalInput<rustc_middle::ty::generic_args::GenericArg>)>>::call_once
        16: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::ty::generic_args::GenericArg>, rustc_middle::query::erase::ErasedData<[u8; 8]>>, false>
        17: rustc_query_impl::query_vtables::try_normalize_generic_arg_after_erasing_regions::execute_query_non_incr::__rust_end_short_backtrace
        18: <rustc_middle::ty::normalize_erasing_regions::TryNormalizeAfterErasingRegionsFolder as rustc_type_ir::fold::FallibleTypeFolder<rustc_middle::ty::context::TyCtxt>>::try_fold_const
        19: <rustc_hir_typeck::writeback::EagerlyNormalizeConsts as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const
        20: <rustc_middle::ty::Ty as rustc_type_ir::fold::TypeSuperFoldable<rustc_middle::ty::context::TyCtxt>>::super_fold_with::<rustc_hir_typeck::writeback::EagerlyNormalizeConsts>
        21: <rustc_hir_typeck::writeback::WritebackCx>::visit_node_id
        22: <rustc_hir_typeck::fn_ctxt::FnCtxt>::resolve_type_vars_in_body
        23: rustc_hir_typeck::typeck_with_inspect::{closure#0}
        24: rustc_query_impl::query_vtables::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
        25: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 8]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        26: rustc_query_impl::query_vtables::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
        27: rustc_hir_analysis::check_crate
        28: rustc_interface::passes::analysis
        29: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 0]>>, false>
        30: rustc_query_impl::query_vtables::analysis::execute_query_non_incr::__rust_end_short_backtrace
        31: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}
        32: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        33: <std::thread::lifecycle::spawn_unchecked<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        34: <std::sys::thread::unix::Thread>::new::thread_start
        35: <unknown>
        36: <unknown>
      
  --> /tmp/icemaker_global_tempdir.LHp6rrJaEQyb/rustc_testrunner_tmpdir_reporting.XILLXqwBzPqr/mvce.rs:13:5
   |
13 |     const SIZE: usize = 4;
   |     ^^^^^^^^^^^^^^^^^

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.100.0-nightly (def3ee9e4 2026-08-22) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

@rustbot label +F-min_generic_const_args +F-macroless_generic_const_args +F-generic_const_args +F-generic_const_exprs

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

Start with the reproducer in the issue and inspect rustc_hir_analysis/src/collect.rs:1693, where the delayed ICE originates. Run the provided snippet on the referenced nightly compiler and trace the const_of_item query through the listed query stack. Done means the example no longer emits this internal compiler error while preserving appropriate diagnostics.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.