Skip to content

ICE with -Znext-solver=globally: index out of bounds #142866

Open
@cyrgani

Description

@cyrgani

Code

This is derived from #142863 and ICEs only with -Znext-solver=globally.

trait Trait<T> {}
struct A<T>(T);
struct B<T>(T);

trait IncompleteGuidance {}

impl<T> Trait<()> for A<T>
where
    T: IncompleteGuidance,
{
}

impl<T, U> Trait<()> for B<T>
where
    A<T>: Trait<U>,
{
}

fn impls_trait<T: Trait<()>>() {}

fn main() {
    impls_trait::<B<()>>();
}

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (d4e1159b8 2025-06-21)
binary: rustc
commit-hash: d4e1159b8c97478778b09a4cc1c7adce5653b8bf
commit-date: 2025-06-21
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.7

Error output

<output>
Backtrace

error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
  --> src/main.rs:13:9
   |
13 | impl<T, U> Trait<()> for B<T>
   |         ^ unconstrained type parameter

thread 'rustc' panicked at /rust/deps/ena-0.14.3/src/snapshot_vec.rs:199:10:
index out of bounds: the len is 1 but the index is 1
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: <rustc_infer::infer::InferCtxt>::shallow_resolve
   4: <rustc_infer::infer::InferCtxt>::resolve_vars_if_possible::<rustc_type_ir::binder::Binder<rustc_middle::ty::context::TyCtxt, rustc_type_ir::predicate::TraitPredicate<rustc_middle::ty::context::TyCtxt>>>
   5: <rustc_trait_selection::error_reporting::TypeErrCtxt>::note_obligation_cause_code::<rustc_span::ErrorGuaranteed, rustc_middle::ty::predicate::Predicate>
   6: <rustc_trait_selection::error_reporting::TypeErrCtxt>::note_obligation_cause
   7: <rustc_trait_selection::error_reporting::TypeErrCtxt>::report_selection_error
   8: <rustc_trait_selection::error_reporting::TypeErrCtxt>::report_fulfillment_errors
   9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_call
  10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_block
  12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  13: rustc_hir_typeck::check::check_fn
  14: rustc_hir_typeck::typeck_with_inspect::{closure#0}
      [... omitted 1 frame ...]
  15: rustc_hir_analysis::check_crate
  16: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  17: 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}
  18: 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 `/home/ansgar/code/tmp/ffff/rustc-ice-2025-06-22T08_22_47-15436.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -Z next-solver=globally

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack

Metadata

Metadata

Labels

C-bugCategory: This is a bug.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.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions