Skip to content

[ICE]: could not replace AliasTerm #155035

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: -Znext-solver=globally
trait Foo {
    type V;
}

trait Callback<T: Foo>: Fn(&A, &T::V) {}

struct Bar<T: Foo> {
    callback: Box<dyn Callback<T>>,
}

impl Bar<T> {
    fn event(&self) {
        (self.callback)(any(), any());
    }
}

struct A;
struct B;

original:

//@ check-pass

fn any<T>() -> T {
    (self.callback)(any(), any());
}

trait Foo {
    type V;
}

trait Callback<T: Foo>: Fn(&A, &T::V) {}
impl<T: , F: Fn(&T, &T::V)> Callback<T> for F {}

struct Bar<T: Foo> {
    callback: Box<dyn Callback<T>>,
}

impl<F: Fn(&T, &T::V)> Bar<T> {
    fn event(&self) {
        (self.callback)(any(), any());
    }
}

struct A;
struct B;
impl Foo for A {
    type V = B;
}

fn main() {
    let  = Bar::<A> { event: Box::new(|_: &B, _: &B| ()) };
    foo.callback();
}

Version information

rustc 1.96.0-nightly (1948ee19e 2026-04-09)
binary: rustc
commit-hash: 1948ee19e95ef7835624c591eef11a8838b66ec7
commit-date: 2026-04-09
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.2

Possibly related line of code:

// so we can replace it with the projection predicate's term.
let mut matching_projections = replacements
.iter()
.filter(|source_projection| self.projection_may_match(**source_projection, alias_term));
let Some(replacement) = matching_projections.next() else {
// This shouldn't happen.
panic!("could not replace {alias_term:?} with term from from {:?}", self.self_ty);
};
// FIXME: This *may* have issues with duplicated projections.
if matching_projections.next().is_some() {
// If there's more than one projection that we can unify here, then we
// need to stall until inference constrains things so that there's only
// one choice.

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

Program output

error[E0425]: cannot find type `T` in this scope
  --> /tmp/icemaker_global_tempdir.ysOO6rHN80by/rustc_testrunner_tmpdir_reporting.8k9YwfZF6if1/mvce.rs:11:10
   |
11 | impl Bar<T> {
   |          ^
...
17 | struct A;
   | --------- similarly named struct `A` defined here
   |
help: a struct with a similar name exists
   |
11 - impl Bar<T> {
11 + impl Bar<A> {
   |
help: you might be missing a type parameter
   |
11 | impl<T> Bar<T> {
   |     +++

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.ysOO6rHN80by/rustc_testrunner_tmpdir_reporting.8k9YwfZF6if1/mvce.rs:18:10
   |
18 | struct B;
   |          ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.ysOO6rHN80by/rustc_testrunner_tmpdir_reporting.8k9YwfZF6if1/mvce.rs`

error[E0425]: cannot find function `any` in this scope
  --> /tmp/icemaker_global_tempdir.ysOO6rHN80by/rustc_testrunner_tmpdir_reporting.8k9YwfZF6if1/mvce.rs:13:25
   |
13 |         (self.callback)(any(), any());
   |                         ^^^ not found in this scope

error[E0425]: cannot find function `any` in this scope
  --> /tmp/icemaker_global_tempdir.ysOO6rHN80by/rustc_testrunner_tmpdir_reporting.8k9YwfZF6if1/mvce.rs:13:32
   |
13 |         (self.callback)(any(), any());
   |                                ^^^ not found in this scope


thread 'rustc' (1321666) panicked at /rustc-dev/1948ee19e95ef7835624c591eef11a8838b66ec7/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs:985:13:
could not replace AliasTerm { args: [dyn [Binder { value: Trait(Callback<{type error}>), bound_vars: [] }, Binder { value: Projection(ExistentialProjection { def_id: DefId(2:4376 ~ core[a753]::ops::function::FnOnce::Output), args: [(&'^0.Named(DefId(0:16 ~ mvce[a523]::Callback::'_)) A, &'^1.Named(DefId(0:17 ~ mvce[a523]::Callback::'_#1)) ?0t)], term: Term::Ty(()), .. }), bound_vars: [Region(BrNamed(DefId(0:16 ~ mvce[a523]::Callback::'_))), Region(BrNamed(DefId(0:17 ~ mvce[a523]::Callback::'_#1)))] }] + '?0, (&'?3 A, &'?4 Alias(AliasTy { args: [{type error}], kind: Projection { def_id: DefId(0:4 ~ mvce[a523]::Foo::V) }, .. }))], def_id: DefId(2:4376 ~ core[a753]::ops::function::FnOnce::Output), .. } with term from from dyn [Binder { value: Trait(Callback<{type error}>), bound_vars: [] }, Binder { value: Projection(ExistentialProjection { def_id: DefId(2:4376 ~ core[a753]::ops::function::FnOnce::Output), args: [(&'^0.Named(DefId(0:16 ~ mvce[a523]::Callback::'_)) A, &'^1.Named(DefId(0:17 ~ mvce[a523]::Callback::'_#1)) ?0t)], term: Term::Ty(()), .. }), bound_vars: [Region(BrNamed(DefId(0:16 ~ mvce[a523]::Callback::'_))), Region(BrNamed(DefId(0:17 ~ mvce[a523]::Callback::'_#1)))] }] + '?0
stack backtrace:
   0:     0x7f8e473e685b - <<std[afe9d9a8c7c60344]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[a753eb1c755cef5d]::fmt::Display>::fmt
   1:     0x7f8e47a1df88 - core[a753eb1c755cef5d]::fmt::write
   2:     0x7f8e473fdb26 - <std[afe9d9a8c7c60344]::sys::stdio::unix::Stderr as std[afe9d9a8c7c60344]::io::Write>::write_fmt
   3:     0x7f8e473bcb58 - std[afe9d9a8c7c60344]::panicking::default_hook::{closure#0}
   4:     0x7f8e473d9ec3 - std[afe9d9a8c7c60344]::panicking::default_hook
   5:     0x7f8e463db2bc - std[afe9d9a8c7c60344]::panicking::update_hook::<alloc[ad0d6ab31f3a4629]::boxed::Box<rustc_driver_impl[417fcbfcaea66ef1]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f8e473da1a2 - std[afe9d9a8c7c60344]::panicking::panic_with_hook
   7:     0x7f8e473bcc18 - std[afe9d9a8c7c60344]::panicking::panic_handler::{closure#0}
   8:     0x7f8e473b1179 - std[afe9d9a8c7c60344]::sys::backtrace::__rust_end_short_backtrace::<std[afe9d9a8c7c60344]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f8e473be67d - __rustc[e13175df4d110ca]::rust_begin_unwind
  10:     0x7f8e440543fc - core[a753eb1c755cef5d]::panicking::panic_fmt
  11:     0x7f8e47de8d2c - <rustc_next_trait_solver[9db06752ac638b31]::solve::assembly::structural_traits::ReplaceProjectionWith<rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt, rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate> as rustc_type_ir[ac4d499b034a9e62]::fold::FallibleTypeFolder<rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::try_fold_ty
  12:     0x7f8e47de81a7 - <&rustc_middle[20c1f01b7ae5e16e]::ty::list::RawList<(), rustc_middle[20c1f01b7ae5e16e]::ty::generic_args::GenericArg> as rustc_type_ir[ac4d499b034a9e62]::fold::TypeFoldable<rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::try_fold_with::<rustc_next_trait_solver[9db06752ac638b31]::solve::assembly::structural_traits::ReplaceProjectionWith<rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt, rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate>>
  13:     0x7f8e48ba1593 - rustc_next_trait_solver[9db06752ac638b31]::solve::assembly::structural_traits::predicates_for_object_candidate::<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate, rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>
  14:     0x7f8e4870212d - <rustc_type_ir[ac4d499b034a9e62]::predicate::TraitPredicate<rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt> as rustc_next_trait_solver[9db06752ac638b31]::solve::assembly::GoalKind<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate, rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::match_assumption::<<rustc_type_ir[ac4d499b034a9e62]::predicate::TraitPredicate<rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt> as rustc_next_trait_solver[9db06752ac638b31]::solve::assembly::GoalKind<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate, rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::probe_and_consider_object_bound_candidate::{closure#0}>
  15:     0x7f8e486f97c8 - <rustc_type_ir[ac4d499b034a9e62]::predicate::TraitPredicate<rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt> as rustc_next_trait_solver[9db06752ac638b31]::solve::assembly::GoalKind<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate, rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::probe_and_consider_object_bound_candidate
  16:     0x7f8e486fd160 - <rustc_next_trait_solver[9db06752ac638b31]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate, rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::compute_trait_goal
  17:     0x7f8e48705822 - <rustc_next_trait_solver[9db06752ac638b31]::solve::search_graph::SearchGraphDelegate<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate> as rustc_type_ir[ac4d499b034a9e62]::search_graph::Delegate>::compute_goal::{closure#0}
  18:     0x7f8e4871e4f7 - <rustc_next_trait_solver[9db06752ac638b31]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate, rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::evaluate_goal_raw
  19:     0x7f8e4870c492 - <rustc_next_trait_solver[9db06752ac638b31]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate, rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::try_evaluate_added_goals
  20:     0x7f8e484ac1dc - <rustc_next_trait_solver[9db06752ac638b31]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate, rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::evaluate_added_goals_and_make_canonical_response
  21:     0x7f8e4870116c - <rustc_next_trait_solver[9db06752ac638b31]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate, rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::assemble_impl_candidates::<rustc_type_ir[ac4d499b034a9e62]::predicate::TraitPredicate<rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::{closure#0}
  22:     0x7f8e486fc6eb - <rustc_next_trait_solver[9db06752ac638b31]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate, rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::compute_trait_goal
  23:     0x7f8e487065f1 - <rustc_next_trait_solver[9db06752ac638b31]::solve::search_graph::SearchGraphDelegate<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate> as rustc_type_ir[ac4d499b034a9e62]::search_graph::Delegate>::compute_goal::{closure#0}
  24:     0x7f8e48703f97 - <rustc_type_ir[ac4d499b034a9e62]::search_graph::SearchGraph<rustc_next_trait_solver[9db06752ac638b31]::solve::search_graph::SearchGraphDelegate<rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate>, rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>>::evaluate_goal_in_task
  25:     0x7f8e48703a91 - rustc_trait_selection[51cb1d2c2f8b0266]::solve::evaluate_root_goal_for_proof_tree_raw
  26:     0x7f8e487038d8 - rustc_query_impl[8effcd60942cb632]::query_impl::evaluate_root_goal_for_proof_tree_raw::invoke_provider_fn::__rust_begin_short_backtrace
  27:     0x7f8e48bf712e - rustc_query_impl[8effcd60942cb632]::execution::try_execute_query::<rustc_middle[20c1f01b7ae5e16e]::query::caches::DefaultCache<rustc_type_ir[ac4d499b034a9e62]::canonical::CanonicalQueryInput<rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt, rustc_type_ir[ac4d499b034a9e62]::solve::QueryInput<rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt, rustc_middle[20c1f01b7ae5e16e]::ty::predicate::Predicate>>, rustc_middle[20c1f01b7ae5e16e]::query::erase::ErasedData<[u8; 48usize]>>, false>
  28:     0x7f8e48bf6d81 - rustc_query_impl[8effcd60942cb632]::query_impl::evaluate_root_goal_for_proof_tree_raw::execute_query_non_incr::__rust_end_short_backtrace
  29:     0x7f8e4849c97a - <rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt as rustc_type_ir[ac4d499b034a9e62]::interner::Interner>::evaluate_root_goal_for_proof_tree_raw
  30:     0x7f8e4849bb72 - <rustc_trait_selection[51cb1d2c2f8b0266]::solve::delegate::SolverDelegate as rustc_next_trait_solver[9db06752ac638b31]::solve::eval_ctxt::SolverDelegateEvalExt>::evaluate_root_goal_for_proof_tree
  31:     0x7f8e48ba85b8 - <rustc_trait_selection[51cb1d2c2f8b0266]::solve::inspect::analyse::InspectCandidate>::instantiate_proof_tree_for_nested_goal
  32:     0x7f8e48ba7f17 - <rustc_trait_selection[51cb1d2c2f8b0266]::solve::inspect::analyse::InspectCandidate>::instantiate_nested_goals
  33:     0x7f8e48ba2f21 - <rustc_trait_selection[51cb1d2c2f8b0266]::solve::fulfill::derive_errors::BestObligation as rustc_trait_selection[51cb1d2c2f8b0266]::solve::inspect::analyse::ProofTreeVisitor>::visit_goal
  34:     0x7f8e48ba2bb0 - <rustc_infer[48df5be7bacb8dbb]::infer::InferCtxt as rustc_trait_selection[51cb1d2c2f8b0266]::solve::inspect::analyse::InferCtxtProofTreeExt>::visit_proof_tree_at_depth::<rustc_trait_selection[51cb1d2c2f8b0266]::solve::fulfill::derive_errors::BestObligation>
  35:     0x7f8e48b9eb17 - rustc_trait_selection[51cb1d2c2f8b0266]::solve::fulfill::derive_errors::find_best_leaf_obligation
  36:     0x7f8e48b9e16b - <rustc_trait_selection[51cb1d2c2f8b0266]::traits::FulfillmentError as rustc_infer[48df5be7bacb8dbb]::traits::engine::FromSolverError<rustc_trait_selection[51cb1d2c2f8b0266]::solve::fulfill::NextSolverError>>::from_solver_error
  37:     0x7f8e4871581c - <rustc_trait_selection[51cb1d2c2f8b0266]::solve::fulfill::FulfillmentCtxt<rustc_trait_selection[51cb1d2c2f8b0266]::traits::FulfillmentError> as rustc_infer[48df5be7bacb8dbb]::traits::engine::TraitEngine<rustc_trait_selection[51cb1d2c2f8b0266]::traits::FulfillmentError>>::try_evaluate_obligations
  38:     0x7f8e484a46de - <rustc_infer[48df5be7bacb8dbb]::infer::at::At as rustc_trait_selection[51cb1d2c2f8b0266]::traits::structural_normalize::StructurallyNormalizeExt>::structurally_normalize_ty::<rustc_trait_selection[51cb1d2c2f8b0266]::traits::FulfillmentError>
  39:     0x7f8e47d1417f - <rustc_hir_typeck[2fa64ffae7bdfde2]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  40:     0x7f8e47d0d6d7 - <rustc_hir_typeck[2fa64ffae7bdfde2]::fn_ctxt::FnCtxt>::check_expr_block
  41:     0x7f8e47d12779 - <rustc_hir_typeck[2fa64ffae7bdfde2]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  42:     0x7f8e482d4940 - rustc_hir_typeck[2fa64ffae7bdfde2]::check::check_fn
  43:     0x7f8e48c878ae - rustc_hir_typeck[2fa64ffae7bdfde2]::typeck_with_inspect::{closure#0}
  44:     0x7f8e48c862b0 - rustc_query_impl[8effcd60942cb632]::query_impl::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
  45:     0x7f8e47abcbe6 - rustc_query_impl[8effcd60942cb632]::execution::try_execute_query::<rustc_data_structures[7c28faee0eb7aaa5]::vec_cache::VecCache<rustc_span[e2aab30ab9650ce5]::def_id::LocalDefId, rustc_middle[20c1f01b7ae5e16e]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[20c1f01b7ae5e16e]::dep_graph::graph::DepNodeIndex>, false>
  46:     0x7f8e47abc403 - rustc_query_impl[8effcd60942cb632]::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
  47:     0x7f8e482dd36e - <rustc_middle[20c1f01b7ae5e16e]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[3df5212d1a56976]::check_crate::{closure#1}>::{closure#0}
  48:     0x7f8e482dcd5f - rustc_hir_analysis[3df5212d1a56976]::check_crate
  49:     0x7f8e47ab92e1 - rustc_interface[f2e03cdea6df0bf4]::passes::analysis
  50:     0x7f8e48c27209 - rustc_query_impl[8effcd60942cb632]::execution::try_execute_query::<rustc_middle[20c1f01b7ae5e16e]::query::caches::SingleCache<rustc_middle[20c1f01b7ae5e16e]::query::erase::ErasedData<[u8; 0usize]>>, false>
  51:     0x7f8e48c26e75 - rustc_query_impl[8effcd60942cb632]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  52:     0x7f8e48c4f4de - rustc_interface[f2e03cdea6df0bf4]::interface::run_compiler::<(), rustc_driver_impl[417fcbfcaea66ef1]::run_compiler::{closure#0}>::{closure#1}
  53:     0x7f8e48c055fe - std[afe9d9a8c7c60344]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[f2e03cdea6df0bf4]::util::run_in_thread_with_globals<rustc_interface[f2e03cdea6df0bf4]::util::run_in_thread_pool_with_globals<rustc_interface[f2e03cdea6df0bf4]::interface::run_compiler<(), rustc_driver_impl[417fcbfcaea66ef1]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  54:     0x7f8e48c05ea0 - <std[afe9d9a8c7c60344]::thread::lifecycle::spawn_unchecked<rustc_interface[f2e03cdea6df0bf4]::util::run_in_thread_with_globals<rustc_interface[f2e03cdea6df0bf4]::util::run_in_thread_pool_with_globals<rustc_interface[f2e03cdea6df0bf4]::interface::run_compiler<(), rustc_driver_impl[417fcbfcaea66ef1]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[a753eb1c755cef5d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  55:     0x7f8e48c06dac - <std[afe9d9a8c7c60344]::sys::thread::unix::Thread>::new::thread_start
  56:     0x7f8e426a597a - <unknown>
  57:     0x7f8e427292bc - <unknown>
  58:                0x0 - <unknown>

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: rustc 1.96.0-nightly (1948ee19e 2026-04-09) running on x86_64-unknown-linux-gnu

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

query stack during panic:
#0 [evaluate_root_goal_for_proof_tree_raw] computing proof tree for `<alloc::boxed::Box<dyn Callback<{type error}, Output = ()>> as core::ops::function::FnOnce<({type error}, {type error})>>::Output normalizes-to ^c_2`
#1 [typeck_root] type-checking `<impl at /tmp/icemaker_global_tempdir.ysOO6rHN80by/rustc_testrunner_tmpdir_reporting.8k9YwfZF6if1/mvce.rs:11:1: 11:12>::event`
#2 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 4 previous errors

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

@rustbot label +WG-trait-system-refactor

Metadata

Metadata

Assignees

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)needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions