rust-lang / rust-lang/rust-analyzer

Crash on const generics code

Open
#23,035 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-ty B-unstable C-bug I-panic
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: 0.4.2999-standalone (6817dd3094 2026-08-05)

rustc version: rustc 1.99.0-nightly (1ed2df61a 2026-08-04)

editor or extension: VSCode

code snippet to reproduce:

// main.rs
#![allow(incomplete_features)]
#![feature(min_generic_const_args, macroless_generic_const_args)]
trait T0 {
    type const N: usize;
}
struct S0<T: T0>([(); T::N]);

fn f1<T: T0>(_: &S0<T>) {}
fn f0<T: T0>(f: &S0<T>) {
    f1(f);
}

fn main() {}
> rust-analyzer analysis-stats .

Database loaded:     333.66ms, 0b (metadata 197.76ms, 0b; build 16.73ms, 0b)
  item trees: 1
  dependency lines of code: 1_469_547, item trees: 2_948
  dependency item stats: traits: 849, impl: 9_703, mods: 3_058, macro calls: 5_590, macro rules: 1_051
Item Tree Collection: 1.22s, 0b
  Total Statistics:
    crates: 1, mods: 1, decls: 5, bodies: 3, adts: 1, consts: 0, signatures: 5, variants: 1
  Workspace:
    traits: 1, macro_rules macros: 0, proc_macros: 0
    lines of code: 14, item trees: 1
    usages: traits: 1, impl: 0, mods: 0, macro calls: 0, macro rules: 0
  Dependencies:
    lines of code: 1_469_547, item trees: 2_948
    declarations: traits: 849, impl: 9_703, mods: 3_058, macro calls: 5_590, macro rules: 1_051
Item Collection:     560.98ms, 0b
Crate lang items:    176.81ms, 0b
Expression Store Lowering: 176.96µs, 0b

thread 'main' (2869738) panicked at /Users/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ena-0.14.4/src/snapshot_vec.rs:199:10:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: <ra_ap_rustc_next_trait_solver::resolve::EagerResolver<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner> as ra_ap_rustc_type_ir::fold::TypeFolder<hir_ty::next_solver::interner::DbInterner>>::fold_ty
   4: <hir_ty::next_solver::generic_arg::GenericArgs as ra_ap_rustc_type_ir::fold::TypeFoldable<hir_ty::next_solver::interner::DbInterner>>::fold_with::<ra_ap_rustc_next_trait_solver::resolve::EagerResolver<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>
   5: <ra_ap_rustc_type_ir::solve::Goal<hir_ty::next_solver::interner::DbInterner, hir_ty::next_solver::predicate::Predicate> as ra_ap_rustc_type_ir::fold::TypeFoldable<hir_ty::next_solver::interner::DbInterner>>::fold_with::<ra_ap_rustc_next_trait_solver::resolve::EagerResolver<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>
   6: ra_ap_rustc_next_trait_solver::resolve::eager_resolve_vars::<hir_ty::next_solver::solver::SolverContext, (ra_ap_rustc_type_ir::solve::Goal<hir_ty::next_solver::interner::DbInterner, hir_ty::next_solver::predicate::Predicate>, alloc::vec::Vec<(ra_ap_rustc_type_ir::opaque_ty::OpaqueTypeKey<hir_ty::next_solver::interner::DbInterner>, hir_ty::next_solver::ty::Ty)>)>
   7: <hir_ty::next_solver::solver::SolverContext as ra_ap_rustc_next_trait_solver::solve::eval_ctxt::SolverDelegateEvalExt>::evaluate_root_goal_for_proof_tree
   8: <hir_ty::next_solver::infer::InferCtxt>::select
   9: hir_ty::method_resolution::lookup_impl_assoc_item_for_trait_ref
  10: hir_ty::method_resolution::lookup_impl_const
  11: <hir_ty::mir::eval::Evaluator>::eval_operand
  12: <hir_ty::mir::eval::Evaluator>::eval_rvalue
  13: hir_ty::mir::eval::interpret_mir
  14: <hir_ty::consteval::anon_const_eval::_::anon_const_eval_query_Configuration_ as salsa::function::Configuration>::execute
  15: <salsa::function::IngredientImpl<hir_ty::consteval::anon_const_eval::_::anon_const_eval_query_Configuration_>>::execute
  16: hir_ty::consteval::anon_const_eval
  17: <hir_ty::next_solver::solver::SolverContext as ra_ap_rustc_next_trait_solver::delegate::SolverDelegate>::evaluate_const
  18: <ra_ap_rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>::evaluate_const_and_instantiate_normalizes_to_term
  19: <ra_ap_rustc_type_ir::search_graph::SearchGraph<ra_ap_rustc_next_trait_solver::solve::search_graph::SearchGraphDelegate<hir_ty::next_solver::solver::SolverContext>, hir_ty::next_solver::interner::DbInterner>>::evaluate_goal_in_task
  20: <ra_ap_rustc_type_ir::search_graph::SearchGraph<ra_ap_rustc_next_trait_solver::solve::search_graph::SearchGraphDelegate<hir_ty::next_solver::solver::SolverContext>, hir_ty::next_solver::interner::DbInterner>>::evaluate_goal
  21: <ra_ap_rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>::try_evaluate_added_goals
  22: <ra_ap_rustc_type_ir::search_graph::SearchGraph<ra_ap_rustc_next_trait_solver::solve::search_graph::SearchGraphDelegate<hir_ty::next_solver::solver::SolverContext>, hir_ty::next_solver::interner::DbInterner>>::evaluate_goal_in_task
  23: <ra_ap_rustc_type_ir::search_graph::SearchGraph<ra_ap_rustc_next_trait_solver::solve::search_graph::SearchGraphDelegate<hir_ty::next_solver::solver::SolverContext>, hir_ty::next_solver::interner::DbInterner>>::evaluate_goal
  24: <ra_ap_rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>::evaluate_goal
  25: <ra_ap_rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>::try_evaluate_added_goals
  26: <ra_ap_rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>::evaluate_added_goals_and_make_canonical_response
  27: <ra_ap_rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>::compute_trait_goal
  28: <ra_ap_rustc_type_ir::search_graph::SearchGraph<ra_ap_rustc_next_trait_solver::solve::search_graph::SearchGraphDelegate<hir_ty::next_solver::solver::SolverContext>, hir_ty::next_solver::interner::DbInterner>>::evaluate_goal_in_task
  29: <ra_ap_rustc_type_ir::search_graph::SearchGraph<ra_ap_rustc_next_trait_solver::solve::search_graph::SearchGraphDelegate<hir_ty::next_solver::solver::SolverContext>, hir_ty::next_solver::interner::DbInterner>>::evaluate_goal
  30: <ra_ap_rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>::evaluate_goal
  31: <ra_ap_rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>::try_evaluate_added_goals
  32: <ra_ap_rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>::evaluate_added_goals_and_make_canonical_response
  33: <ra_ap_rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>::assemble_impl_candidates::<ra_ap_rustc_type_ir::predicate::TraitPredicate<hir_ty::next_solver::interner::DbInterner>>::{closure#0}
  34: <ra_ap_rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<hir_ty::next_solver::solver::SolverContext, hir_ty::next_solver::interner::DbInterner>>::compute_trait_goal
  35: <ra_ap_rustc_type_ir::search_graph::SearchGraph<ra_ap_rustc_next_trait_solver::solve::search_graph::SearchGraphDelegate<hir_ty::next_solver::solver::SolverContext>, hir_ty::next_solver::interner::DbInterner>>::evaluate_goal_in_task
  36: <hir_ty::infer::coerce::Coerce<hir_ty::infer::coerce::InferenceCoercionDelegate>>::coerce
  37: <hir_ty::infer::InferenceContext>::check_call_arguments
  38: <hir_ty::infer::InferenceContext>::infer_call
  39: <hir_ty::infer::InferenceContext>::infer_expr_inner
  40: <hir_ty::infer::InferenceContext>::infer_expr_inner
  41: <hir_ty::infer::InferenceContext>::infer_return
  42: hir_ty::infer::infer_query_with_inspect
  43: <salsa::function::IngredientImpl<<hir_ty::infer::InferenceResult>::for_body::_::for_body__Configuration_>>::execute
  44: <hir_ty::infer::InferenceResult>::for_body
  45: <rust_analyzer::cli::flags::AnalysisStats>::run_inference
  46: <rust_analyzer::cli::flags::AnalysisStats>::run::{closure#4}
  47: <rust_analyzer::cli::flags::AnalysisStats>::run
  48: rust_analyzer::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
infer panicked for bugrepro::f0: index out of bounds: the len is 0 but the index is 0
  exprs: 2, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0
  pats: 1, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0
  panics: 1
Inference:           111.18ms, 0b
2026-08-05T14:27:04.550361-05:00  WARN Propagating panic for cycle head that panicked in an earlier execution in that revision

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

Run the provided const-generics snippet with rust-analyzer analysis-stats . and confirm the panic. Trace the stack through hir_ty::next_solver, method_resolution, consteval, and inference, then ensure this reproducer no longer panics and has regression coverage.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.