Skip to content

[ICE]: Const default value for generic arg with generic_const_exprs enabled #156240

@irh

Description

@irh

Code

#![feature(generic_const_exprs)]

pub const DEFAULT: usize = 1;

pub struct Foo<const N: usize = DEFAULT>
where
    [(); N]:;

Any of the following avoid the ICE:

  • Remove #![feature(generic_const_exprs)]
  • Remove the default value for N
  • Use a literal for the default value.

Meta

rustc +nightly --version --verbose:

rustc 1.97.0-nightly (e95e73209 2026-05-05)
binary: rustc
commit-hash: e95e73209faf6ead2bc5c7636e45e589a751b79b
commit-date: 2026-05-05
host: aarch64-apple-darwin
release: 1.97.0-nightly
LLVM version: 22.1.4

Error output

thread 'rustc' (20220379) panicked at /rustc-dev/e95e73209faf6ead2bc5c7636e45e589a751b79b/compiler/rustc_type_ir/src/binder.rs:650:13:
Binder { value: WellFormed(Term::Ty([(); N/#0])), bound_vars: [] } has parameters, but no args were provided in instantiate
Backtrace

thread 'rustc' panicked at /rustc-dev/e95e73209faf6ead2bc5c7636e45e589a751b79b/compiler/rustc_type_ir/src/binder.rs:650:13:
Binder { value: WellFormed(Term::Ty([(); N/#0])), bound_vars: [] } has parameters, but no args were provided in instantiate
stack backtrace:
   0:        0x11232ab7c - <std[ba95dd84dcb40fd7]::backtrace::Backtrace>::create
   1:        0x110071354 - std[ba95dd84dcb40fd7]::panicking::update_hook::<alloc[ec32cc677de768a9]::boxed::Box<rustc_driver_impl[75493f1677804ab4]::install_ice_hook::{closure#1}>>::{closure#0}
   2:        0x11233c204 - std[ba95dd84dcb40fd7]::panicking::panic_with_hook
   3:        0x112320194 - std[ba95dd84dcb40fd7]::panicking::panic_handler::{closure#0}
   4:        0x112316b2c - std[ba95dd84dcb40fd7]::sys::backtrace::__rust_end_short_backtrace::<std[ba95dd84dcb40fd7]::panicking::panic_handler::{closure#0}, !>
   5:        0x112321768 - __rustc[2d5b6cc7a58c455b]::rust_begin_unwind
   6:        0x11535d7dc - core[c57fb36d3ad3ee2e]::panicking::panic_fmt
   7:        0x110e11ae8 - <rustc_middle[ab6b1a3552af91dc]::ty::generics::GenericPredicates>::instantiate_into
   8:        0x111efc738 - <rustc_trait_selection[9d548477726ada75]::traits::wf::WfPredicates>::nominal_obligations
   9:        0x11206a980 - <rustc_trait_selection[9d548477726ada75]::traits::wf::WfPredicates as rustc_type_ir[c95de3f73f8a6ff6]::visit::TypeVisitor<rustc_middle[ab6b1a3552af91dc]::ty::context::TyCtxt>>::visit_const
  10:        0x111fab828 - rustc_trait_selection[9d548477726ada75]::traits::wf::obligations
  11:        0x1120057f4 - <rustc_trait_selection[9d548477726ada75]::traits::fulfill::FulfillProcessor as rustc_data_structures[35118fcc2dc17860]::obligation_forest::ObligationProcessor>::process_obligation
  12:        0x111da83d8 - <rustc_data_structures[35118fcc2dc17860]::obligation_forest::ObligationForest<rustc_trait_selection[9d548477726ada75]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[9d548477726ada75]::traits::fulfill::FulfillProcessor>
  13:        0x111ff45e4 - <rustc_trait_selection[9d548477726ada75]::traits::fulfill::FulfillmentContext<rustc_trait_selection[9d548477726ada75]::traits::FulfillmentError> as rustc_infer[b3b270f64b54bdb1]::traits::engine::TraitEngine<rustc_trait_selection[9d548477726ada75]::traits::FulfillmentError>>::try_evaluate_obligations
  14:        0x11208c2b0 - <rustc_trait_selection[9d548477726ada75]::traits::fulfill::FulfillmentContext<rustc_trait_selection[9d548477726ada75]::traits::FulfillmentError> as rustc_infer[b3b270f64b54bdb1]::traits::engine::TraitEngine<rustc_trait_selection[9d548477726ada75]::traits::FulfillmentError>>::evaluate_obligations_error_on_ambiguity
  15:        0x1104313c0 - rustc_hir_analysis[ff46227b1a672aeb]::check::wfcheck::check_type_defn
  16:        0x110419858 - rustc_hir_analysis[ff46227b1a672aeb]::check::check::check_item_type
  17:        0x110435dc8 - rustc_hir_analysis[ff46227b1a672aeb]::check::wfcheck::check_well_formed
  18:        0x1118b1814 - rustc_query_impl[58a30886da8d1cc3]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  19:        0x1116bc5dc - rustc_query_impl[58a30886da8d1cc3]::execution::try_execute_query::<rustc_data_structures[35118fcc2dc17860]::vec_cache::VecCache<rustc_span[f43e87c4afd786b9]::def_id::LocalDefId, rustc_middle[ab6b1a3552af91dc]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[ab6b1a3552af91dc]::dep_graph::graph::DepNodeIndex>, true>
  20:        0x1118b179c - rustc_query_impl[58a30886da8d1cc3]::query_impl::check_well_formed::execute_query_incr::__rust_end_short_backtrace
  21:        0x11042ab10 - rustc_hir_analysis[ff46227b1a672aeb]::check::wfcheck::check_type_wf
  22:        0x1118a35cc - rustc_query_impl[58a30886da8d1cc3]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  23:        0x1116eb19c - rustc_query_impl[58a30886da8d1cc3]::execution::try_execute_query::<rustc_middle[ab6b1a3552af91dc]::query::caches::SingleCache<rustc_middle[ab6b1a3552af91dc]::query::erase::ErasedData<[u8; 1usize]>>, true>
  24:        0x1118a355c - rustc_query_impl[58a30886da8d1cc3]::query_impl::check_type_wf::execute_query_incr::__rust_end_short_backtrace
  25:        0x11036fb18 - rustc_hir_analysis[ff46227b1a672aeb]::check_crate
  26:        0x1109f7da4 - rustc_interface[8a26816c23be435d]::passes::analysis
  27:        0x1116e5c40 - rustc_query_impl[58a30886da8d1cc3]::execution::try_execute_query::<rustc_middle[ab6b1a3552af91dc]::query::caches::SingleCache<rustc_middle[ab6b1a3552af91dc]::query::erase::ErasedData<[u8; 0usize]>>, true>
  28:        0x1118d86d8 - rustc_query_impl[58a30886da8d1cc3]::query_impl::analysis::execute_query_incr::__rust_end_short_backtrace
  29:        0x110028660 - rustc_interface[8a26816c23be435d]::passes::create_and_enter_global_ctxt::<core[c57fb36d3ad3ee2e]::option::Option<rustc_interface[8a26816c23be435d]::queries::Linker>, rustc_driver_impl[75493f1677804ab4]::run_compiler::{closure#0}::{closure#2}>
  30:        0x1100702e4 - rustc_interface[8a26816c23be435d]::interface::run_compiler::<(), rustc_driver_impl[75493f1677804ab4]::run_compiler::{closure#0}>::{closure#1}
  31:        0x110067fc4 - std[ba95dd84dcb40fd7]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[8a26816c23be435d]::util::run_in_thread_with_globals<rustc_interface[8a26816c23be435d]::util::run_in_thread_pool_with_globals<rustc_interface[8a26816c23be435d]::interface::run_compiler<(), rustc_driver_impl[75493f1677804ab4]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  32:        0x110077e44 - <std[ba95dd84dcb40fd7]::thread::lifecycle::spawn_unchecked<rustc_interface[8a26816c23be435d]::util::run_in_thread_with_globals<rustc_interface[8a26816c23be435d]::util::run_in_thread_pool_with_globals<rustc_interface[8a26816c23be435d]::interface::run_compiler<(), rustc_driver_impl[75493f1677804ab4]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[c57fb36d3ad3ee2e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:        0x112346a20 - <std[ba95dd84dcb40fd7]::sys::thread::unix::Thread>::new::thread_start
  34:        0x18db6bc58 - __pthread_cond_wait


rustc version: 1.97.0-nightly (e95e73209 2026-05-05)
platform: aarch64-apple-darwin

query stack during panic:
#0 [check_well_formed] checking that `Foo` is well-formed
#1 [check_type_wf] checking that types are well-formed
#2 [analysis] running analysis passes on crate `rust_const_generics_ice`
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions