Skip to content

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

Closed

Description

@matthiaskrgr

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:

// inference guidance that makes other goals go from ambig -> pass, for example.
//
// FIXME: We should probably just look into overflows here.
false,
),
Ok(GoalEvaluation { certainty: Certainty::Yes, .. }) => {
span_bug!(
root_obligation.cause.span,
"did not expect successful goal when collecting ambiguity errors for `{:?}`",
infcx.resolve_vars_if_possible(root_obligation.predicate),
)
}
Err(_) => {

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

Activity

  1. added
    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.
    C-bugCategory: This is a bug.
    on Jan 25, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)
    on Jan 25, 2026
  3. matthiaskrgr commented on Jan 25, 2026

    @matthiaskrgr
    MemberAuthor
    trait Trait<'a, 'b> {}
    trait OtherTrait<'b> {}
    impl<'a, T: OtherTrait /*<'a>*/> Trait<'a, 'b> for T {}
    fn impl_hr<'b, T: for<'a> Trait<'a, 'b>>() {}
    fn not_hr<'a, T: OtherTrait /*<'a>*/ + OtherTrait<'static>>() {
        impl_hr::<T>;
    }
    fn main() {}
  4. adwinwhite commented on Aug 13, 2026

    @adwinwhite
    Contributor

    This no longer causes ICE with the next solver.

  5. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 13, 2026
  6. lcnr commented on Oct 8, 2026

    @lcnr
    Contributor

    this issue has been certainly fixed with #162782 merged which also adds relevant tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions