rust-lang / rust-lang/rust

[ICE]: `erroneous constant missed by mono item collection`

Open
#162,337 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-generic_const_args F-min_generic_const_args 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(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:
https://github.com/rust-lang/rust/blob/0f819a1602c3814642aa63799b43772b7bb456e8/compiler/rustc_codegen_ssa/src/mir/constant.rs#L22-L34

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

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 by reproducing the supplied a.rs snippet with the shown nightly rustc command. Read compiler/rustc_codegen_ssa/src/mir/constant.rs around lines 22-34, then trace the reported constant through monomorphization and the delayed trait-solver error. Done means this input no longer causes 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
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.