rust-lang / rust-lang/rust

ICE: `type parameter `T/#1` (T/#1/1) out of range when instantiating, args=[?2t]`

Open
#141,919 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-associated_const_equality fixed-by-next-solver I-ICE S-has-bisection S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code

Hand-reduced

#![feature(associated_const_equality)]

trait Trait {
    type TT;
}

pub struct NoPin;

pub trait PinA<PER> {
    const A: u8;
}

impl<PER> PinA<PER> for NoPin {
    const A: u8 = 0;
}

pub trait Pins<USART> {}

impl<USART, T> Pins<USART> for T where T: PinA<USART, A = 42> {}

struct S<T> {
    x: T,
}

impl<T> S<&dyn Trait> where NoPin: Pins<T> {}

fn main() {}

A mutant of tests/ui/generic-const-items/assoc-const-AnonConst-ice-108220.rs

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (99e7c15e8 2025-06-01)
binary: rustc
commit-hash: 99e7c15e81385b38a8186b51edc4577d5d7b5bdd
commit-date: 2025-06-01
host: aarch64-apple-darwin
release: 1.89.0-nightly
LLVM version: 20.1.5
Error output

command: rustc

error[E0191]: the value of the associated type `TT` in `Trait` must be specified
  --> afidt_1_c2.rs:25:16
   |
4  |     type TT;
   |     ------- `TT` defined here
...
25 | impl<T> S<&dyn Trait> where NoPin: Pins<T> {}
   |                ^^^^^ help: specify the associated type: `Trait<TT = Type>`


thread 'rustc' panicked at /rustc/99e7c15e81385b38a8186b51edc4577d5d7b5bdd/compiler/rustc_type_ir/src/binder.rs:753:9:
type parameter `T/#1` (T/#1/1) out of range when instantiating, args=[?2t]
Backtrace

thread 'rustc' panicked at /rustc/99e7c15e81385b38a8186b51edc4577d5d7b5bdd/compiler/rustc_type_ir/src/binder.rs:753:9:
type parameter `T/#1` (T/#1/1) out of range when instantiating, args=[?2t]
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt>>::type_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::list::RawList<(), rustc_middle::ty::generic_args::GenericArg> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::fold_with::<rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt>>
   5: <rustc_middle::ty::consts::Const as rustc_type_ir::fold::TypeSuperFoldable<rustc_middle::ty::context::TyCtxt>>::super_fold_with::<rustc_type_ir::binder::ArgFolder<rustc_middle::ty::context::TyCtxt>>
   6: rustc_trait_selection::traits::project::opt_normalize_projection_term
   7: <rustc_infer::infer::InferCtxt>::commit_if_ok::<rustc_trait_selection::traits::project::ProjectAndUnifyResult, rustc_infer::traits::project::MismatchedProjectionTypes, rustc_trait_selection::traits::project::poly_project_and_unify_term::{closure#0}>
   8: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_predicate_recursively::{closure#0}::{closure#0}
   9: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_predicate_recursively
  10: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_candidate::{closure#0}::{closure#0}
  11: <rustc_infer::infer::InferCtxt>::probe::<core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>, <rustc_trait_selection::traits::select::SelectionContext>::evaluation_probe<<rustc_trait_selection::traits::select::SelectionContext>::evaluate_candidate::{closure#0}::{closure#0}>::{closure#0}>
  12: <rustc_trait_selection::traits::select::SelectionContext>::in_task::<<rustc_trait_selection::traits::select::SelectionContext>::candidate_from_obligation::{closure#0}::{closure#0}, core::result::Result<core::option::Option<rustc_middle::traits::select::SelectionCandidate>, rustc_middle::traits::SelectionError>>::{closure#0}
  13: <rustc_trait_selection::traits::select::SelectionContext>::candidate_from_obligation
  14: <rustc_trait_selection::traits::select::SelectionContext>::poly_select::{closure#0}
  15: <rustc_trait_selection::traits::fulfill::FulfillProcessor>::process_trait_obligation
  16: <rustc_trait_selection::traits::fulfill::FulfillProcessor as rustc_data_structures::obligation_forest::ObligationProcessor>::process_obligation
  17: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor>
  18: <rustc_trait_selection::traits::fulfill::FulfillmentContext<rustc_trait_selection::traits::FulfillmentError> as rustc_infer::traits::engine::TraitEngine<rustc_trait_selection::traits::FulfillmentError>>::select_where_possible
  19: <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
  20: rustc_hir_analysis::check::wfcheck::check_item
  21: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
  22: <rustc_middle::hir::ModuleItems>::par_opaques::<rustc_hir_analysis::check::wfcheck::check_mod_type_wf::{closure#4}>::{closure#0}
  23: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 1 frame ...]
  24: rustc_hir_analysis::check_crate
  25: rustc_interface::passes::run_required_analyses
  26: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  27: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  28: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: please attach the file at `/Users/jisukbyun/workspace/250203 scratch/rustc-ice-2025-06-02T15_09_43-2051.txt` to your bug report

query stack during panic:
#0 [check_well_formed] checking that `<impl at afidt_1_c2.rs:25:1: 25:43>` 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
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0191`.

Bisects to

searched nightlies: from nightly-2025-01-01 to nightly-2025-06-01
regressed nightly: nightly-2025-05-24
searched commit range: https://github.com/rust-lang/rust/compare/2eef47813f25df637026ce3288880e5c587abd92...3e674b06b5c74adea662bd0b0b06450757994b16
regressed commit: https://github.com/rust-lang/rust/commit/52bf0cf795dfecc8b929ebb1c1e2545c3f41d4c9

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --end=2025-06-01 --regress ice --preserve --script rustc -- afidt_1_c2.rs
Notes

@rustbot label +F-associated_const_equality

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 hand-reduced reproducer in afidt_1_c2.rs and confirm the ICE with the listed cargo bisect-rustc command. Then read compiler/rustc_type_ir/src/binder.rs around line 753 and follow the query stack through well-formedness checking and trait selection. Done means the example reports the expected diagnostic without panicking.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.