rust-lang / rust-lang/rust

Internal Compiler Error with generic const parameters

Open
#136,416 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-generic_const_exprs I-ICE P-low S-bug-has-test T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

rustc-ice-2025-02-02T02_19_03-370381.txt

Code
#![feature(generic_const_exprs)]
struct State<const S : usize = {}> where[(); S] :;

I think this should be a parser error? I reduced it from a much more complicated test case that I think was hitting an actual logic bug, but this is the smallest program that triggers a failure in the same way.

Meta

rustc --version --verbose:

rustc 1.86.0-nightly (8239a37f9 2025-02-01)
binary: rustc
commit-hash: 8239a37f9c0951a037cfc51763ea52a20e71e6bd
commit-date: 2025-02-01
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7
Error output
query stack during panic:
#0 [check_well_formed] checking that `State` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
Backtrace

thread 'rustc' panicked at /rustc/8239a37f9c0951a037cfc51763ea52a20e71e6bd/compiler/rustc_type_ir/src/binder.rs:776:9:
const parameter `S/#0` (S/#0/0) out of range when instantiating args=[]
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt>>::const_param_out_of_range
   3: <rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt> as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_ty
   4: <rustc_middle::ty::generics::GenericPredicates>::instantiate_into
   5: <rustc_trait_selection::traits::wf::WfPredicates>::nominal_obligations
   6: <rustc_trait_selection::traits::wf::WfPredicates as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_const
   7: <rustc_trait_selection::traits::fulfill::FulfillProcessor as rustc_data_structures::obligation_forest::ObligationProcessor>::process_obligation
   8: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor>
   9: <rustc_trait_selection::traits::fulfill::FulfillmentContext<rustc_trait_selection::traits::FulfillmentError> as rustc_infer::traits::engine::TraitEngine<rustc_trait_selection::traits::FulfillmentError>>::select_all_or_error
  10: rustc_hir_analysis::check::wfcheck::check_type_defn
  11: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
  12: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 1 frame ...]
  13: rustc_hir_analysis::check_crate
  14: rustc_interface::passes::run_required_analyses
  15: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  16: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  17: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}

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 compiling the reduced example and confirming the ICE and query stack. Read compiler/rustc_type_ir/src/binder.rs around line 776 and the rustc_hir_analysis well-formedness path named in the backtrace. Done means the example produces an appropriate parser or compiler diagnostic without panicking, with a regression test covering it.

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
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.