Skip to content

[ICE]: erroneous constant missed by mono item collection #162337

Description

@matthiaskrgr

snippet:

#![feature(min_generic_const_args)]
#![feature(generic_const_args)]
use std::marker::PhantomData;
struct Meta<A> {
    value: i32,
    type_: PhantomData<A>,
}
trait MetaTrait {
    fn get_value(&self) -> i32;
}
impl<A> MetaTrait for Meta<A> {
    fn get_value(&self) -> i32 {
        self.value
    }
}
trait Bar {
    fn get_const(&self) -> &dyn MetaTrait;
}
struct Foo<A> {
    _value: A,
}
impl<A: 'static> Foo<A> {
    const CONST: &'static dyn MetaTrait = &Meta::<Self> {
        value: 0,
        type_: PhantomData,
    };
}
impl<A: 'static> Bar for Foo<A> {
    fn get_const(&self) -> &dyn MetaTrait {
        Self::CONST
    }
}
fn main() {
    let foo = Foo { _value: 0 };
    let bar: &dyn Bar = &foo;
}

Version information

rustc 1.100.0-nightly (0f819a160 2026-09-05)
binary: rustc
commit-hash: 0f819a1602c3814642aa63799b43772b7bb456e8
commit-date: 2026-09-05
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.1

Possibly related line of code:

pub fn eval_mir_constant(&self, constant: &mir::ConstOperand<'tcx>) -> mir::ConstValue {
// `MirUsedCollector` visited all required_consts before codegen began, so if we got here
// there can be no more constants that fail to evaluate.
self.monomorphize(constant.const_)
.eval(self.cx.tcx(), self.cx.typing_env(), constant.span)
.expect("erroneous constant missed by mono item collection")
}
/// This is a convenience helper for `immediate_const_vector`. It has the precondition
/// that the given `constant` is an `Const::Unevaluated` and must be convertible to
/// a `ValTree`. If you want a more general version of this, talk to `wg-const-eval` on zulip.
///

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

warning: unused variable: `bar`
  --> /tmp/icemaker_global_tempdir.W8zf5G15qrBF/rustc_testrunner_tmpdir_reporting.i732SDZP4VwW/mvce.rs:35:9
   |
35 |     let bar: &dyn Bar = &foo;
   |         ^^^ help: if this is intentional, prefix it with an underscore: `_bar`
   |
   = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

warning: struct `Meta` is never constructed
 --> /tmp/icemaker_global_tempdir.W8zf5G15qrBF/rustc_testrunner_tmpdir_reporting.i732SDZP4VwW/mvce.rs:4:8
  |
4 | struct Meta<A> {
  |        ^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: trait `MetaTrait` is never used
 --> /tmp/icemaker_global_tempdir.W8zf5G15qrBF/rustc_testrunner_tmpdir_reporting.i732SDZP4VwW/mvce.rs:8:7
  |
8 | trait MetaTrait {
  |       ^^^^^^^^^

warning: method `get_const` is never used
  --> /tmp/icemaker_global_tempdir.W8zf5G15qrBF/rustc_testrunner_tmpdir_reporting.i732SDZP4VwW/mvce.rs:17:8
   |
16 | trait Bar {
   |       --- method in this trait
17 |     fn get_const(&self) -> &dyn MetaTrait;
   |        ^^^^^^^^^

warning: associated constant `CONST` is never used
  --> /tmp/icemaker_global_tempdir.W8zf5G15qrBF/rustc_testrunner_tmpdir_reporting.i732SDZP4VwW/mvce.rs:23:11
   |
22 | impl<A: 'static> Foo<A> {
   | ----------------------- associated constant in this implementation
23 |     const CONST: &'static dyn MetaTrait = &Meta::<Self> {
   |           ^^^^^


thread 'rustc' (1181182) panicked at /rustc-dev/0f819a1602c3814642aa63799b43772b7bb456e8/compiler/rustc_codegen_ssa/src/mir/constant.rs:28:14:
erroneous constant missed by mono item collection: Reported(ReportedErrorInfo { error: ErrorGuaranteed(()), allowed_in_infallible: true }, no-location (#0))
stack backtrace:
   0:     0x7f14610c54e6 - <<std[739b682464b2cb4f]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[d997ca8b291862e0]::fmt::Display>::fmt
   1:     0x7f146180ba4f - core[d997ca8b291862e0]::fmt::write
   2:     0x7f14610da5cc - <std[739b682464b2cb4f]::sys::stdio::unix::Stderr as core[d997ca8b291862e0]::io::write::Write>::write_fmt
   3:     0x7f1461097d8a - std[739b682464b2cb4f]::panicking::default_hook::{closure#0}
   4:     0x7f14610b97e3 - std[739b682464b2cb4f]::panicking::default_hook
   5:     0x7f146000943f - std[739b682464b2cb4f]::panicking::update_hook::<alloc[cfd194cf86e92e23]::boxed::Box<rustc_driver_impl[4b133f65db23c9ab]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f14610b9c82 - std[739b682464b2cb4f]::panicking::panic_with_hook
   7:     0x7f1461097e42 - std[739b682464b2cb4f]::panicking::panic_handler::{closure#0}
   8:     0x7f146108ecb9 - std[739b682464b2cb4f]::sys::backtrace::__rust_end_short_backtrace::<std[739b682464b2cb4f]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f1461099a1d - __rustc[e7cd4045d256b0b7]::rust_begin_unwind
  10:     0x7f145de5c07c - core[d997ca8b291862e0]::panicking::panic_fmt
  11:     0x7f145d21dc22 - core[d997ca8b291862e0]::result::unwrap_failed
  12:     0x7f1462e88598 - <rustc_codegen_ssa[8f26ed03727e8a44]::mir::FunctionCx<rustc_codegen_llvm[bd153491abf07e3a]::builder::GenericBuilder<rustc_codegen_llvm[bd153491abf07e3a]::context::FullCx>>>::codegen_operand
  13:     0x7f1462e55d6a - rustc_codegen_ssa[8f26ed03727e8a44]::mir::codegen_mir::<rustc_codegen_llvm[bd153491abf07e3a]::builder::GenericBuilder<rustc_codegen_llvm[bd153491abf07e3a]::context::FullCx>>
  14:     0x7f1461b43f9e - rustc_codegen_llvm[bd153491abf07e3a]::base::compile_codegen_unit::module_codegen
  15:     0x7f14629ab676 - <rustc_codegen_llvm[bd153491abf07e3a]::LlvmCodegenBackend as rustc_codegen_ssa[8f26ed03727e8a44]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  16:     0x7f14629a7616 - rustc_codegen_ssa[8f26ed03727e8a44]::base::codegen_crate::<rustc_codegen_llvm[bd153491abf07e3a]::LlvmCodegenBackend, rustc_codegen_llvm[bd153491abf07e3a]::ModuleLlvm>
  17:     0x7f14629a5f0c - <rustc_codegen_llvm[bd153491abf07e3a]::LlvmCodegenBackend as rustc_codegen_ssa[8f26ed03727e8a44]::traits::backend::CodegenBackend>::codegen_crate
  18:     0x7f1462ba750c - <rustc_interface[69481172a0b187c3]::queries::Linker>::codegen_and_build_linker
  19:     0x7f1462b9eb81 - rustc_interface[69481172a0b187c3]::interface::run_compiler::<(), rustc_driver_impl[4b133f65db23c9ab]::run_compiler::{closure#0}>::{closure#2}
  20:     0x7f1462c03164 - std[739b682464b2cb4f]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[69481172a0b187c3]::util::run_in_thread_with_globals<rustc_interface[69481172a0b187c3]::util::run_in_thread_pool_with_globals<rustc_interface[69481172a0b187c3]::interface::run_compiler<(), rustc_driver_impl[4b133f65db23c9ab]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  21:     0x7f1462c02f0b - <std[739b682464b2cb4f]::thread::lifecycle::spawn_unchecked<rustc_interface[69481172a0b187c3]::util::run_in_thread_with_globals<rustc_interface[69481172a0b187c3]::util::run_in_thread_pool_with_globals<rustc_interface[69481172a0b187c3]::interface::run_compiler<(), rustc_driver_impl[4b133f65db23c9ab]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[d997ca8b291862e0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  22:     0x7f1462c00947 - <std[739b682464b2cb4f]::sys::thread::unix::Thread>::new::thread_start
  23:     0x7f145bc980a2 - <unknown>
  24:     0x7f145bd2080c - <unknown>
  25:                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: rustc 1.100.0-nightly (0f819a160 2026-09-05) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
warning: 7 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: Type system constant with non valtree'able type evaluated but no error emitted
  |
  = note: delayed at /rustc-dev/0f819a1602c3814642aa63799b43772b7bb456e8/compiler/rustc_trait_selection/src/traits/mod.rs:776:39
             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>::delayed_bug::<&str>
             4: <rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt>>::evaluate_const
             5: <rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt>>::evaluate_const_and_instantiate_projection_term
             6: <rustc_type_ir::search_graph::SearchGraph<rustc_next_trait_solver::solve::search_graph::SearchGraphDelegate<rustc_trait_selection::solve::delegate::SolverDelegate>, rustc_middle::ty::context::TyCtxt>>::evaluate_goal::{closure#0}
             7: <rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt>>::evaluate_goal_no_fast_paths
             8: <rustc_next_trait_solver::normalize::NormalizationFolder<rustc_infer::infer::InferCtxt, rustc_middle::ty::context::TyCtxt, rustc_trait_selection::solve::normalize::normalize_with_universes<rustc_middle::ty::generic_args::GenericArg>::{closure#0}>>::normalize_alias_term
             9: <rustc_next_trait_solver::normalize::NormalizationFolder<rustc_infer::infer::InferCtxt, rustc_middle::ty::context::TyCtxt, rustc_trait_selection::solve::normalize::normalize_with_universes<rustc_middle::ty::generic_args::GenericArg>::{closure#0}> as rustc_type_ir::fold::FallibleTypeFolder<rustc_middle::ty::context::TyCtxt>>::try_fold_const::{closure#0}
            10: <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
            11: 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>
            12: rustc_query_impl::query_vtables::try_normalize_generic_arg_after_erasing_regions::execute_query_non_incr::__rust_end_short_backtrace
            13: <rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder>::normalize_generic_arg_after_erasing_regions
            14: <rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const
            15: rustc_monomorphize::collector::items_of_instance
            16: rustc_query_impl::query_vtables::items_of_instance::invoke_provider_fn::__rust_begin_short_backtrace
            17: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefaultCache<(rustc_middle::ty::instance::Instance, rustc_middle::mono::CollectionMode), rustc_middle::query::erase::ErasedData<[u8; 32]>>, false>
            18: rustc_query_impl::query_vtables::items_of_instance::execute_query_non_incr::__rust_end_short_backtrace
            19: rustc_monomorphize::collector::collect_items_rec
            20: rustc_monomorphize::collector::collect_items_rec
            21: rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}
            22: rustc_monomorphize::partitioning::collect_and_partition_mono_items
            23: rustc_query_impl::query_vtables::collect_and_partition_mono_items::invoke_provider_fn::__rust_begin_short_backtrace
            24: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 24]>>, false>
            25: rustc_query_impl::query_vtables::collect_and_partition_mono_items::execute_query_non_incr::__rust_end_short_backtrace
            26: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend, rustc_codegen_llvm::ModuleLlvm>
            27: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
            28: <rustc_interface::queries::Linker>::codegen_and_build_linker
            29: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}
            30: 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}, ()>
            31: <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}
            32: <std::sys::thread::unix::Thread>::new::thread_start
            33: <unknown>
            34: <unknown>
          

error: internal compiler error: Unevaluated `ty::Const` in MIR body
  |
  = note: delayed at /rustc-dev/0f819a1602c3814642aa63799b43772b7bb456e8/compiler/rustc_middle/src/mir/consts.rs:339:35
             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>::delayed_bug::<&str>
             4: rustc_monomorphize::collector::items_of_instance
             5: rustc_query_impl::query_vtables::items_of_instance::invoke_provider_fn::__rust_begin_short_backtrace
             6: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefaultCache<(rustc_middle::ty::instance::Instance, rustc_middle::mono::CollectionMode), rustc_middle::query::erase::ErasedData<[u8; 32]>>, false>
             7: rustc_query_impl::query_vtables::items_of_instance::execute_query_non_incr::__rust_end_short_backtrace
             8: rustc_monomorphize::collector::collect_items_rec
             9: rustc_monomorphize::collector::collect_items_rec
            10: rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}
            11: rustc_monomorphize::partitioning::collect_and_partition_mono_items
            12: rustc_query_impl::query_vtables::collect_and_partition_mono_items::invoke_provider_fn::__rust_begin_short_backtrace
            13: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 24]>>, false>
            14: rustc_query_impl::query_vtables::collect_and_partition_mono_items::execute_query_non_incr::__rust_end_short_backtrace
            15: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend, rustc_codegen_llvm::ModuleLlvm>
            16: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
            17: <rustc_interface::queries::Linker>::codegen_and_build_linker
            18: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}
            19: 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}, ()>
            20: <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}
            21: <std::sys::thread::unix::Thread>::new::thread_start
            22: <unknown>
            23: <unknown>
          

error: internal compiler error: Unevaluated `ty::Const` in MIR body
  |
  = note: delayed at /rustc-dev/0f819a1602c3814642aa63799b43772b7bb456e8/compiler/rustc_middle/src/mir/consts.rs:339:35
             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_codegen_ssa::mir::FunctionCx<rustc_codegen_llvm::builder::GenericBuilder<rustc_codegen_llvm::context::FullCx>>>::codegen_operand
             4: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::GenericBuilder<rustc_codegen_llvm::context::FullCx>>
             5: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
             6: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit
             7: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend, rustc_codegen_llvm::ModuleLlvm>
             8: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
             9: <rustc_interface::queries::Linker>::codegen_and_build_linker
            10: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}
            11: 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}, ()>
            12: <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}
            13: <std::sys::thread::unix::Thread>::new::thread_start
            14: <unknown>
            15: <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.100.0-nightly (0f819a160 2026-09-05) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

@rustbot label +F-min_generic_const_args +F-generic_const_args

Activity

  1. added
    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.
    C-bugCategory: This is a bug.
    on Sep 5, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    F-gca_const_items`#![feature(gca_const_items)]` (previously: `generic_const_args`)
    F-gca_min_const_items`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)
    on Sep 5, 2026
  3. Dnreikronos commented on Sep 27, 2026

    @Dnreikronos
    Contributor

    I took a look at this one. The original snippet doesn't ICE on master anymore, but I think that's kind of by accident. After #162923 only trait consts get lowered as type system consts in MIR under gca_const_items, and Self::CONST here is an inherent const, so it just goes the normal way now. (also the features got renamed in the meantime, so the snippet needs gca_min_const_items and gca_const_items now)

    If you swap it for a trait assoc const it still crashes the same way on master

    #![feature(gca_min_const_items, gca_const_items)]
    #![allow(incomplete_features)]
    
    trait MetaTrait {}
    impl MetaTrait for () {}
    
    trait HasConst {
        const CONST: &'static dyn MetaTrait;
    }
    
    impl<A: 'static> HasConst for Option<A> {
        const CONST: &'static dyn MetaTrait = &();
    }
    
    fn get<T: HasConst>() -> &'static dyn MetaTrait {
        T::CONST
    }
    
    fn main() {
        let _ = get::<Option<u8>>();
    }

    From what I can tell the problem is that T::CONST ends up as a Const::Ty in the MIR, so during mono we try to evaluate it through the type system, and that wants a valtree. &dyn MetaTrait can't be a valtree. The code there assumes an error was already reported, so we just get the delayed bug, the const never gets evaluated, and then codegen blows up. fn() and unions do the same thing. A Vec<u8> const (Vec::new()) hits a different one, the "shouldn't have created a ValTree for pattern_type" ICE, which looks like #162336.

    I get why it's lowered like that. An impl can implement a normal trait const with a gca!(...) value, and that one has no MIR body, so a plain Const::Unevaluated wouldn't have anything to evaluate. So just reverting that bit would break that case. I also don't think only doing it when the type is ConstParamTy works, because with something like const C: Self::Out the caller can't really know.

    What I'd like to try is keeping Const::Ty for consts that are always gca! and lowering everything else as Const::Unevaluated again, then dealing with it in const_eval_resolve. Once the instance is resolved we know if the impl is a gca! const (const_of_item returns something), and only then we go through the type system and turn the valtree back into a value. Everything else gets evaluated like any normal const. Personally I like this better because we'd only use valtrees when the impl really is a gca! const, and those already have to be ConstParamTy. It also means turning the feature on doesn't change how regular trait consts behave at runtime, which feels like what the FIXME in the MIR lowering is worried about anyway.

    I haven't written it yet, and I'd rather check with you two first. @khyperia you wrote the #162923 fix that made the lowering look like it does now, and @BoxyUwU you've been driving most of the GCA design. This would move the place where we decide if something is a gca! const, and that FIXME already says it needs another look before stabilization, so I don't want to open a PR that goes against what you have planned for it. Does this sound like the direction you want, or do you have something else in mind? Happy to open a PR if it sounds ok.

  4. khyperia commented on Sep 28, 2026

    @khyperia
    Member

    That is indeed the direction we want to go in, mostly! Prooobably want to lower all ExprKind::NamedConst to Const::Unevaluated, including things that are a gca! const. (tl;dr ExprKind::NamedConst is a regular reference, not a typesystem reference, and Const::Unevaluated means "this is a regular reference", and Const::Ty means "this is a reference to a const that came from the type system")

    However, there are significant theoretical issues that we need to figure out and first, it's not just a matter of writing up a PR (if it was, I would have already done so, I have a draft on my local computer with the exact change you're describing!). I'm planning on writing up what will probably be an uncomfortably long document to share with various t-types people, and having several zulip meetings & calls over this topic.

    Apologies for not linking these two issues together, yes, #162336 (comment) and this issue are basically the same issue. Sorry that you spent so long investigating that, I should have written things down better!

    The original snippet doesn't ICE on master anymore, but I think that's kind of by accident

    on a tangent, it was actually intentional, haha - several people on zulip were complaining about the usability of GCA due to running into this issue, so with #162937 I narrowed the things that trigger the issue down to the bare minimum of what actually needs to encounter the bug, which is projection consts. That PR's title probably gives you an idea, that lowering things to Const::Ty is a hack~

    Also on another tangent, Boxy and I yapped in zulip quite a bit about Const::Ty vs. Const::Unevaluated in this zulip thread, if you're curious about learning more about this problem #project-const-generics > casual chat and support @ 💬 (no idea how coherent our yaps are, but at least they're in public...)

    See also this document Boxy wrote https://hackmd.io/1ZJgp6nSQj-8AgclcB2RAg

  5. Dnreikronos commented on Sep 28, 2026

    @Dnreikronos
    Contributor

    That is indeed the direction we want to go in, mostly! Prooobably want to lower all ExprKind::NamedConst to Const::Unevaluated, including things that are a gca! const. (tl;dr ExprKind::NamedConst is a regular reference, not a typesystem reference, and Const::Unevaluated means "this is a regular reference", and Const::Ty means "this is a reference to a const that came from the type system")

    However, there are significant theoretical issues that we need to figure out and first, it's not just a matter of writing up a PR (if it was, I would have already done so, I have a draft on my local computer with the exact change you're describing!). I'm planning on writing up what will probably be an uncomfortably long document to share with various t-types people, and having several zulip meetings & calls over this topic.

    Apologies for not linking these two issues together, yes, #162336 (comment) and this issue are basically the same issue. Sorry that you spent so long investigating that, I should have written things down better!

    The original snippet doesn't ICE on master anymore, but I think that's kind of by accident

    on a tangent, it was actually intentional, haha - several people on zulip were complaining about the usability of GCA due to running into this issue, so with #162937 I narrowed the things that trigger the issue down to the bare minimum of what actually needs to encounter the bug, which is projection consts. That PR's title probably gives you an idea, that lowering things to Const::Ty is a hack~

    Also on another tangent, Boxy and I yapped in zulip quite a bit about Const::Ty vs. Const::Unevaluated in this zulip thread, if you're curious about learning more about this problem #project-const-generics > casual chat and support @ 💬 (no idea how coherent our yaps are, but at least they're in public...)

    See also this document Boxy wrote https://hackmd.io/1ZJgp6nSQj-8AgclcB2RAg

    Ah okay, that makes a lot of sense, thanks for explaining! And no worries about the time, I learned a bunch about how this part works digging through it, so it wasn't wasted for me at all.

    Lowering every NamedConst to Const::Unevaluated sounds cleaner to me too, honestly. Thinking of it as "a normal reference vs. something that came from the type system" makes the whole thing click way better than how I was looking at it. And fair point on #162937, I read the narrowing as a side effect, but a hack to get people unblocked makes total sense.

    I'm going to read the zulip thread and Boxy's doc, and I'd be happy to follow along when you share the write up with t-types, even if it's just to lurk.

  6. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-gca_const_items`#![feature(gca_const_items)]` (previously: `generic_const_args`)F-gca_min_const_items`#![feature(gca_min_const_items)]` (previously: `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