rust-lang / rust-lang/rust

ICE: `impl .. was matchable against Binder { .. } but now is not`

Open
#150,517 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-trait-system C-bug fixed-by-next-solver I-ICE S-bug-has-test S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

This is a fuzzer-generated bug. Similar to #149015 and all the issues linked from there, but has the following distinct query stack:

#0 [typeck] type-checking `StreamExt::f`
#1 [analysis] running analysis passes on crate `matchable`

Reduced using treereduce-rust.

Code
trait Stream {
    type Item;
    fn next(self) -> ();
}
impl Stream for &'a mut () {}
impl<'a, A, F, T> Stream for <&mut A as Stream>::Item {}
trait StreamExt {
    fn f(self) -> usize
    where
        for<'b> &'b mut A: Stream,
    {
        self.next
    }
}
Meta

rustc --version --verbose:

rustc 1.94.0-nightly (56f24e00c 2025-12-29)
binary: rustc
commit-hash: 56f24e00c62ec2db9a8b407e7aef532caaf71062
commit-date: 2025-12-29
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8
Error output
error: internal compiler error: /rustc-dev/56f24e00c62ec2db9a8b407e7aef532caaf71062/compiler/rustc_trait_selection/src/traits/select/mod.rs:2496:17: impl DefId(0:7 ~ matchable[44a1]::{impl#1}) was matchable against Binder { value: TraitPredicate(<Self as Stream>, polarity:Positive), bound_vars: [] } but now is not
Backtrace

error[E0261]: use of undeclared lifetime name `'a`
 --> matchable.rs:5:18
  |
5 | impl Stream for &'a mut () {}
  |                  ^^ undeclared lifetime
  |
help: consider introducing lifetime `'a` here
  |
5 | impl<'a> Stream for &'a mut () {}
  |     ++++

error[E0425]: cannot find type `A` in this scope
  --> matchable.rs:10:25
   |
10 |         for<'b> &'b mut A: Stream,
   |                         ^ not found in this scope

error[E0601]: `main` function not found in crate `matchable`
  --> matchable.rs:14:2
   |
14 | }
   |  ^ consider adding a `main` function to `matchable.rs`

error[E0207]: the type parameter `A` is not constrained by the impl trait, self type, or predicates
 --> matchable.rs:6:10
  |
6 | impl<'a, A, F, T> Stream for <&mut A as Stream...
  |          ^ unconstrained type parameter

error[E0207]: the type parameter `F` is not constrained by the impl trait, self type, or predicates
 --> matchable.rs:6:13
  |
6 | impl<'a, A, F, T> Stream for <&mut A as Stream...
  |             ^ unconstrained type parameter

error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
 --> matchable.rs:6:16
  |
6 | ...A, F, T> Stream for <&mut A as Stream>::Ite...
  |          ^ unconstrained type parameter

error: internal compiler error: /rustc-dev/56f24e00c62ec2db9a8b407e7aef532caaf71062/compiler/rustc_trait_selection/src/traits/select/mod.rs:2496:17: impl DefId(0:7 ~ matchable[44a1]::{impl#1}) was matchable against Binder { value: TraitPredicate(<Self as Stream>, polarity:Positive), bound_vars: [] } but now is not


thread 'rustc' (27136) panicked at /rustc-dev/56f24e00c62ec2db9a8b407e7aef532caaf71062/compiler/rustc_trait_selection/src/traits/select/mod.rs:2496:17:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_trait_selection::traits::select::SelectionContext>::confirm_candidate
   7: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
   8: <rustc_trait_selection::traits::select::SelectionContext>::evaluation_probe::<<rustc_trait_selection::traits::select::SelectionContext>::evaluate_root_obligation::{closure#0}>::{closure#0}
   9: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow
  10: <rustc_infer::infer::InferCtxt>::probe::<rustc_hir_typeck::method::probe::ProbeResult, <rustc_hir_typeck::method::probe::ProbeContext>::consider_probe::{closure#0}::{closure#0}>
  11: <rustc_hir_typeck::method::probe::ProbeContext>::pick_all_method
  12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::probe_for_name
  13: <rustc_hir_typeck::fn_ctxt::FnCtxt>::method_exists_for_diagnostic
  14: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_field
  15: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  16: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_block
  17: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  18: rustc_hir_typeck::check::check_fn
  19: rustc_hir_typeck::typeck_with_inspect::{closure#0}
      [... omitted 1 frame ...]
  20: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis::check_crate::{closure#2}>::{closure#0}
  21: rustc_hir_analysis::check_crate
  22: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  23: <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} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  24: 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.

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/langston/code/drice/rustc-ice-2025-12-30T17_40_54-27133.txt` to your bug report

note: rustc 1.94.0-nightly (56f24e00c 2025-12-29) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `StreamExt::f`
#1 [analysis] running analysis passes on crate `matchable`
end of query stack
error: aborting due to 7 previous errors

Some errors have detailed explanations: E0207, E0261, E0425, E0601.
For more information about an error, try `rustc --explain E0207`.

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 with the reduced Rust code in the issue and reproduce the ICE using the reported query stack, typeck of StreamExt::f and analysis of matchable. Inspect compiler/rustc_trait_selection/src/traits/select/mod.rs around line 2496 and trace the candidate confirmation path. Done means the reproducer no longer triggers the internal compiler error and the behavior is covered by a regression test.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.