rust-lang / rust-lang/rust

[ICE]: ` did not expect successful goal when collecting ambiguity errors`

Open
#151,648 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-ICE T-compiler WG-trait-system-refactor
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

auto-reduced (treereduce-rust):

//@compile-flags: -Znext-solver=globally
trait Trait<'a, 'b> {}

trait OtherTrait<'b> {}
impl<'a, 'a, T: OtherTrait<'b>> Trait<'a, 'b> for T {}

fn impl_hr<'b, T: for<'a> Trait<'a, 'b>>() {}

fn not_hr<'a, T: for<'b> OtherTrait<'a, 'b> + OtherTrait<'static>>() {
    impl_hr::<T>();
}

original:

//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
//@ check-pass

// cc #119820

trait Trait<'a, 'b> {}

trait OtherTrait<'b> {}
impl<'a, 'a, T: OtherTrait<'b>> Trait<'a, 'b> for T {}

fn impl_hr<'b, T: for<'a> Trait<'a, 'b>>() {}

fn not_hr<'a, T: for<'b> OtherTrait<'a, 'b> + OtherTrait<'static>>() {
    impl_hr::<T>();
}

fn main() {}

Version information

rustc 1.95.0-nightly (941585327 2026-01-25)
binary: rustc
commit-hash: 9415853279dda1394c1f7d4114e1fe1e3ced76ec
commit-date: 2026-01-25
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 21.1.8

Possibly related line of code:
https://github.com/rust-lang/rust/blob/9415853279dda1394c1f7d4114e1fe1e3ced76ec/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs#L115-L127

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Znext-solver=globally

Program output

error[E0403]: the name `'a` is already used for a generic parameter in this item's generic parameters
 --> /tmp/icemaker_global_tempdir.T11Rhen9ppY6/rustc_testrunner_tmpdir_reporting.FkrqTiLp60vK/mvce.rs:4:10
  |
4 | impl<'a, 'a, T: OtherTrait<'b>> Trait<'a, 'b> for T {}
  |      --  ^^ already used
  |      |
  |      first use of `'a`

error[E0261]: use of undeclared lifetime name `'b`
 --> /tmp/icemaker_global_tempdir.T11Rhen9ppY6/rustc_testrunner_tmpdir_reporting.FkrqTiLp60vK/mvce.rs:4:43
  |
4 | impl<'a, 'a, T: OtherTrait<'b>> Trait<'a, 'b> for T {}
  |                                           ^^ undeclared lifetime
  |
help: consider introducing lifetime `'b` here
  |
4 | impl<'b, 'a, 'a, T: OtherTrait<'b>> Trait<'a, 'b> for T {}
  |      +++

error[E0261]: use of undeclared lifetime name `'b`
 --> /tmp/icemaker_global_tempdir.T11Rhen9ppY6/rustc_testrunner_tmpdir_reporting.FkrqTiLp60vK/mvce.rs:4:28
  |
4 | impl<'a, 'a, T: OtherTrait<'b>> Trait<'a, 'b> for T {}
  |                            ^^ undeclared lifetime
  |
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'b` lifetime
  |
4 | impl<'a, 'a, T: for<'b> OtherTrait<'b>> Trait<'a, 'b> for T {}
  |                 +++++++
help: consider introducing lifetime `'b` here
  |
4 | impl<'b, 'a, 'a, T: OtherTrait<'b>> Trait<'a, 'b> for T {}
  |      +++

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.T11Rhen9ppY6/rustc_testrunner_tmpdir_reporting.FkrqTiLp60vK/mvce.rs:10:2
   |
10 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.T11Rhen9ppY6/rustc_testrunner_tmpdir_reporting.FkrqTiLp60vK/mvce.rs`

error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supplied
 --> /tmp/icemaker_global_tempdir.T11Rhen9ppY6/rustc_testrunner_tmpdir_reporting.FkrqTiLp60vK/mvce.rs:8:26
  |
8 | fn not_hr<'a, T: for<'b> OtherTrait<'a, 'b> + OtherTrait<'static>>() {
  |                          ^^^^^^^^^^   ---- help: remove the lifetime argument
  |                          |
  |                          expected 1 lifetime argument
  |
note: trait defined here, with 1 lifetime parameter: `'b`
 --> /tmp/icemaker_global_tempdir.T11Rhen9ppY6/rustc_testrunner_tmpdir_reporting.FkrqTiLp60vK/mvce.rs:3:7
  |
3 | trait OtherTrait<'b> {}
  |       ^^^^^^^^^^ --

error: internal compiler error: /rustc-dev/9415853279dda1394c1f7d4114e1fe1e3ced76ec/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs:121:17: did not expect successful goal when collecting ambiguity errors for `Binder { value: TraitPredicate(<T as Trait<'a, '_>>, polarity:Positive), bound_vars: [Region(BrNamed(DefId(0:15 ~ mvce[e936]::impl_hr::'a)))] }`
 --> /tmp/icemaker_global_tempdir.T11Rhen9ppY6/rustc_testrunner_tmpdir_reporting.FkrqTiLp60vK/mvce.rs:9:5
  |
9 |     impl_hr::<T>();
  |     ^^^^^^^^^^^^^^


thread 'rustc' (1267291) panicked at /rustc-dev/9415853279dda1394c1f7d4114e1fe1e3ced76ec/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs:121:17:
Box<dyn Any>
stack backtrace:
   0:     0x7fa633234853 - <<std[d1378798ed0df37d]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[61c54f01bfa55c5f]::fmt::Display>::fmt
   1:     0x7fa63380e688 - core[61c54f01bfa55c5f]::fmt::write
   2:     0x7fa63324afe6 - <std[d1378798ed0df37d]::sys::stdio::unix::Stderr as std[d1378798ed0df37d]::io::Write>::write_fmt
   3:     0x7fa63320a858 - std[d1378798ed0df37d]::panicking::default_hook::{closure#0}
   4:     0x7fa633227fb3 - std[d1378798ed0df37d]::panicking::default_hook
   5:     0x7fa63221535d - std[d1378798ed0df37d]::panicking::update_hook::<alloc[3f0665886d0cb995]::boxed::Box<rustc_driver_impl[e7cd29ff173f18b7]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fa633228292 - std[d1378798ed0df37d]::panicking::panic_with_hook
   7:     0x7fa632249861 - std[d1378798ed0df37d]::panicking::begin_panic::<rustc_errors[4412d669ad9ac0d9]::ExplicitBug>::{closure#0}
   8:     0x7fa632242576 - std[d1378798ed0df37d]::sys::backtrace::__rust_end_short_backtrace::<std[d1378798ed0df37d]::panicking::begin_panic<rustc_errors[4412d669ad9ac0d9]::ExplicitBug>::{closure#0}, !>
   9:     0x7fa6322422ea - std[d1378798ed0df37d]::panicking::begin_panic::<rustc_errors[4412d669ad9ac0d9]::ExplicitBug>
  10:     0x7fa6322549d1 - <rustc_errors[4412d669ad9ac0d9]::diagnostic::BugAbort as rustc_errors[4412d669ad9ac0d9]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7fa6327d97cc - <rustc_errors[4412d669ad9ac0d9]::DiagCtxtHandle>::span_bug::<rustc_span[221d93c9354447ee]::span_encoding::Span, alloc[3f0665886d0cb995]::string::String>
  12:     0x7fa632802076 - rustc_middle[87068083d1557a2c]::util::bug::opt_span_bug_fmt::<rustc_span[221d93c9354447ee]::span_encoding::Span>::{closure#0}
  13:     0x7fa632802222 - rustc_middle[87068083d1557a2c]::ty::context::tls::with_opt::<rustc_middle[87068083d1557a2c]::util::bug::opt_span_bug_fmt<rustc_span[221d93c9354447ee]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7fa6327f384b - rustc_middle[87068083d1557a2c]::ty::context::tls::with_context_opt::<rustc_middle[87068083d1557a2c]::ty::context::tls::with_opt<rustc_middle[87068083d1557a2c]::util::bug::opt_span_bug_fmt<rustc_span[221d93c9354447ee]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7fa630116a58 - rustc_middle[87068083d1557a2c]::util::bug::span_bug_fmt::<rustc_span[221d93c9354447ee]::span_encoding::Span>
  16:     0x7fa634959c25 - <rustc_trait_selection[9c3e7a31c96833d9]::traits::FulfillmentError as rustc_infer[5fb91953f074b4d]::traits::engine::FromSolverError<rustc_trait_selection[9c3e7a31c96833d9]::solve::fulfill::NextSolverError>>::from_solver_error
  17:     0x7fa6343972f3 - <rustc_trait_selection[9c3e7a31c96833d9]::solve::fulfill::FulfillmentCtxt<rustc_trait_selection[9c3e7a31c96833d9]::traits::FulfillmentError> as rustc_infer[5fb91953f074b4d]::traits::engine::TraitEngine<rustc_trait_selection[9c3e7a31c96833d9]::traits::FulfillmentError>>::collect_remaining_errors
  18:     0x7fa6345d19e7 - rustc_hir_typeck[f50ab56e4a53d4fa]::typeck_with_inspect::{closure#0}
  19:     0x7fa6345cbcba - rustc_query_impl[6985c40abc7256ba]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6985c40abc7256ba]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[87068083d1557a2c]::query::erase::Erased<[u8; 8usize]>>
  20:     0x7fa63397bbaa - rustc_query_system[dcb5fa8d85d36a30]::query::plumbing::try_execute_query::<rustc_query_impl[6985c40abc7256ba]::DynamicConfig<rustc_data_structures[b55cda6142c8c008]::vec_cache::VecCache<rustc_span[221d93c9354447ee]::def_id::LocalDefId, rustc_middle[87068083d1557a2c]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[dcb5fa8d85d36a30]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[6985c40abc7256ba]::plumbing::QueryCtxt, false>
  21:     0x7fa63397b489 - rustc_query_impl[6985c40abc7256ba]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  22:     0x7fa633e009ed - <rustc_middle[87068083d1557a2c]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[338edc8e857fcf79]::check_crate::{closure#2}>::{closure#0}
  23:     0x7fa633e003e2 - rustc_hir_analysis[338edc8e857fcf79]::check_crate
  24:     0x7fa63397565b - rustc_interface[52cbc3f18da608ee]::passes::analysis
  25:     0x7fa6339752a5 - rustc_query_impl[6985c40abc7256ba]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6985c40abc7256ba]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[87068083d1557a2c]::query::erase::Erased<[u8; 0usize]>>
  26:     0x7fa63496dd51 - rustc_query_system[dcb5fa8d85d36a30]::query::plumbing::try_execute_query::<rustc_query_impl[6985c40abc7256ba]::DynamicConfig<rustc_query_system[dcb5fa8d85d36a30]::query::caches::SingleCache<rustc_middle[87068083d1557a2c]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[6985c40abc7256ba]::plumbing::QueryCtxt, false>
  27:     0x7fa63496db3c - rustc_query_impl[6985c40abc7256ba]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7fa634b2a514 - <rustc_interface[52cbc3f18da608ee]::passes::create_and_enter_global_ctxt<core[61c54f01bfa55c5f]::option::Option<rustc_interface[52cbc3f18da608ee]::queries::Linker>, rustc_driver_impl[e7cd29ff173f18b7]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[61c54f01bfa55c5f]::ops::function::FnOnce<(&rustc_session[5f2250ac9f179614]::session::Session, rustc_middle[87068083d1557a2c]::ty::context::CurrentGcx, alloc[3f0665886d0cb995]::sync::Arc<rustc_data_structures[b55cda6142c8c008]::jobserver::Proxy>, &std[d1378798ed0df37d]::sync::once_lock::OnceLock<rustc_middle[87068083d1557a2c]::ty::context::GlobalCtxt>, &rustc_data_structures[b55cda6142c8c008]::sync::worker_local::WorkerLocal<rustc_middle[87068083d1557a2c]::arena::Arena>, &rustc_data_structures[b55cda6142c8c008]::sync::worker_local::WorkerLocal<rustc_hir[fb98bda4945cef24]::Arena>, rustc_driver_impl[e7cd29ff173f18b7]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  29:     0x7fa634980e4f - rustc_interface[52cbc3f18da608ee]::interface::run_compiler::<(), rustc_driver_impl[e7cd29ff173f18b7]::run_compiler::{closure#0}>::{closure#1}
  30:     0x7fa6349bc9be - std[d1378798ed0df37d]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[52cbc3f18da608ee]::util::run_in_thread_with_globals<rustc_interface[52cbc3f18da608ee]::util::run_in_thread_pool_with_globals<rustc_interface[52cbc3f18da608ee]::interface::run_compiler<(), rustc_driver_impl[e7cd29ff173f18b7]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  31:     0x7fa6349bcee0 - <std[d1378798ed0df37d]::thread::lifecycle::spawn_unchecked<rustc_interface[52cbc3f18da608ee]::util::run_in_thread_with_globals<rustc_interface[52cbc3f18da608ee]::util::run_in_thread_pool_with_globals<rustc_interface[52cbc3f18da608ee]::interface::run_compiler<(), rustc_driver_impl[e7cd29ff173f18b7]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[61c54f01bfa55c5f]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x7fa6349bdd6c - <std[d1378798ed0df37d]::sys::thread::unix::Thread>::new::thread_start
  33:     0x7fa62e29698b - <unknown>
  34:     0x7fa62e31a9cc - <unknown>
  35:                0x0 - <unknown>

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: rustc 1.95.0-nightly (941585327 2026-01-25) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z next-solver=globally -Z dump-mir-dir=dir

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

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

@rustbot label +WG-trait-system-refactor

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

Reproduce the reduced Rust program with -Znext-solver=globally and confirm the internal compiler error. Then inspect compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs, especially lines 115-127, and trace the ambiguity-error collection entry point. Done means the example no longer triggers an ICE and reports the appropriate result.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.