Skip to content

[ICE]: could not replace AliasTerm (unsatisifed bounds) #151329

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

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

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

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

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

struct A;
struct B;

original:

fn any<T>() -> T { loop {} }

trait Foo { type V; }

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

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

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

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

fn main() {
    let elem = 1i32;
    foo.event();
}

Version information

rustc 1.95.0-nightly (621d76794 2026-01-18)
binary: rustc
commit-hash: 621d76794c76fc21c0a6151fbc090120e0230a91
commit-date: 2026-01-18
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 21.1.8

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[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.P7n4BPAPG2qy/rustc_testrunner_tmpdir_reporting.Ihw4lR5RFRrV/mvce.rs:18:10
   |
18 | struct B;
   |          ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.P7n4BPAPG2qy/rustc_testrunner_tmpdir_reporting.Ihw4lR5RFRrV/mvce.rs`

error[E0277]: the size for values of type `(dyn Callback<T> + 'static)` cannot be known at compilation time
  --> /tmp/icemaker_global_tempdir.P7n4BPAPG2qy/rustc_testrunner_tmpdir_reporting.Ihw4lR5RFRrV/mvce.rs:11:14
   |
11 | impl<T: Foo> Bar<dyn Callback<T>> {
   |              ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `Sized` is not implemented for `(dyn Callback<T> + 'static)`
note: required by an implicit `Sized` bound in `Bar`
  --> /tmp/icemaker_global_tempdir.P7n4BPAPG2qy/rustc_testrunner_tmpdir_reporting.Ihw4lR5RFRrV/mvce.rs:7:12
   |
 7 | struct Bar<T: Foo> {
   |            ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
help: consider relaxing the implicit `Sized` restriction
   |
 7 | struct Bar<T: Foo + ?Sized> {
   |                   ++++++++

error[E0277]: the size for values of type `(dyn Callback<T> + 'static)` cannot be known at compilation time
  --> /tmp/icemaker_global_tempdir.P7n4BPAPG2qy/rustc_testrunner_tmpdir_reporting.Ihw4lR5RFRrV/mvce.rs:12:14
   |
12 |     fn event(&self) {
   |              ^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `Sized` is not implemented for `(dyn Callback<T> + 'static)`
note: required by an implicit `Sized` bound in `Bar`
  --> /tmp/icemaker_global_tempdir.P7n4BPAPG2qy/rustc_testrunner_tmpdir_reporting.Ihw4lR5RFRrV/mvce.rs:7:12
   |
 7 | struct Bar<T: Foo> {
   |            ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
help: consider relaxing the implicit `Sized` restriction
   |
 7 | struct Bar<T: Foo + ?Sized> {
   |                   ++++++++


thread 'rustc' (1999399) panicked at /rustc-dev/621d76794c76fc21c0a6151fbc090120e0230a91/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs:966:13:
could not replace AliasTerm { args: [dyn [Binder { value: Trait(Callback<dyn Callback<!0>>), bound_vars: [] }, Binder { value: Projection(ExistentialProjection { def_id: DefId(2:4226 ~ core[7477]::ops::function::FnOnce::Output), args: [(&'^0.Named(DefId(0:17 ~ mvce[a621]::Callback::'_)) dyn [Binder { value: Trait(Callback<!0>), bound_vars: [] }, Binder { value: Projection(ExistentialProjection { def_id: DefId(2:4226 ~ core[7477]::ops::function::FnOnce::Output), args: [(&'^0.Named(DefId(0:17 ~ mvce[a621]::Callback::'_)) !0, &'^1.Named(DefId(0:18 ~ mvce[a621]::Callback::'_#1)) Alias(Projection, AliasTy { args: [!0], def_id: DefId(0:4 ~ mvce[a621]::Foo::V), .. }))], term: Term::Ty(()), use_existential_projection_new_instead: () }), bound_vars: [Region(BrNamed(DefId(0:17 ~ mvce[a621]::Callback::'_))), Region(BrNamed(DefId(0:18 ~ mvce[a621]::Callback::'_#1)))] }] + '?0, &'^1.Named(DefId(0:18 ~ mvce[a621]::Callback::'_#1)) Alias(Projection, AliasTy { args: [dyn [Binder { value: Trait(Callback<!0>), bound_vars: [] }, Binder { value: Projection(ExistentialProjection { def_id: DefId(2:4226 ~ core[7477]::ops::function::FnOnce::Output), args: [(&'^0.Named(DefId(0:17 ~ mvce[a621]::Callback::'_)) !0, &'^1.Named(DefId(0:18 ~ mvce[a621]::Callback::'_#1)) Alias(Projection, AliasTy { args: [!0], def_id: DefId(0:4 ~ mvce[a621]::Foo::V), .. }))], term: Term::Ty(()), use_existential_projection_new_instead: () }), bound_vars: [Region(BrNamed(DefId(0:17 ~ mvce[a621]::Callback::'_))), Region(BrNamed(DefId(0:18 ~ mvce[a621]::Callback::'_#1)))] }] + '?0], def_id: DefId(0:4 ~ mvce[a621]::Foo::V), .. }))], term: Term::Ty(()), use_existential_projection_new_instead: () }), bound_vars: [Region(BrNamed(DefId(0:17 ~ mvce[a621]::Callback::'_))), Region(BrNamed(DefId(0:18 ~ mvce[a621]::Callback::'_#1)))] }] + '?0, (?0t, ?1t)], def_id: DefId(2:4226 ~ core[7477]::ops::function::FnOnce::Output), .. } with term from from dyn [Binder { value: Trait(Callback<dyn Callback<!0>>), bound_vars: [] }, Binder { value: Projection(ExistentialProjection { def_id: DefId(2:4226 ~ core[7477]::ops::function::FnOnce::Output), args: [(&'^0.Named(DefId(0:17 ~ mvce[a621]::Callback::'_)) dyn [Binder { value: Trait(Callback<!0>), bound_vars: [] }, Binder { value: Projection(ExistentialProjection { def_id: DefId(2:4226 ~ core[7477]::ops::function::FnOnce::Output), args: [(&'^0.Named(DefId(0:17 ~ mvce[a621]::Callback::'_)) !0, &'^1.Named(DefId(0:18 ~ mvce[a621]::Callback::'_#1)) Alias(Projection, AliasTy { args: [!0], def_id: DefId(0:4 ~ mvce[a621]::Foo::V), .. }))], term: Term::Ty(()), use_existential_projection_new_instead: () }), bound_vars: [Region(BrNamed(DefId(0:17 ~ mvce[a621]::Callback::'_))), Region(BrNamed(DefId(0:18 ~ mvce[a621]::Callback::'_#1)))] }] + '?0, &'^1.Named(DefId(0:18 ~ mvce[a621]::Callback::'_#1)) Alias(Projection, AliasTy { args: [dyn [Binder { value: Trait(Callback<!0>), bound_vars: [] }, Binder { value: Projection(ExistentialProjection { def_id: DefId(2:4226 ~ core[7477]::ops::function::FnOnce::Output), args: [(&'^0.Named(DefId(0:17 ~ mvce[a621]::Callback::'_)) !0, &'^1.Named(DefId(0:18 ~ mvce[a621]::Callback::'_#1)) Alias(Projection, AliasTy { args: [!0], def_id: DefId(0:4 ~ mvce[a621]::Foo::V), .. }))], term: Term::Ty(()), use_existential_projection_new_instead: () }), bound_vars: [Region(BrNamed(DefId(0:17 ~ mvce[a621]::Callback::'_))), Region(BrNamed(DefId(0:18 ~ mvce[a621]::Callback::'_#1)))] }] + '?0], def_id: DefId(0:4 ~ mvce[a621]::Foo::V), .. }))], term: Term::Ty(()), use_existential_projection_new_instead: () }), bound_vars: [Region(BrNamed(DefId(0:17 ~ mvce[a621]::Callback::'_))), Region(BrNamed(DefId(0:18 ~ mvce[a621]::Callback::'_#1)))] }] + '?0
stack backtrace:
   0:     0x7f3560233fd3 - <<std[287527946f71f0bc]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[7477a31a1a34cc49]::fmt::Display>::fmt
   1:     0x7f356080e2c8 - core[7477a31a1a34cc49]::fmt::write
   2:     0x7f356024a9c6 - <std[287527946f71f0bc]::sys::stdio::unix::Stderr as std[287527946f71f0bc]::io::Write>::write_fmt
   3:     0x7f356020a048 - std[287527946f71f0bc]::panicking::default_hook::{closure#0}
   4:     0x7f3560227703 - std[287527946f71f0bc]::panicking::default_hook
   5:     0x7f355f1fbb8a - std[287527946f71f0bc]::panicking::update_hook::<alloc[979041e9952e771b]::boxed::Box<rustc_driver_impl[517260a07841a630]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f35602279e2 - std[287527946f71f0bc]::panicking::panic_with_hook
   7:     0x7f356020a108 - std[287527946f71f0bc]::panicking::panic_handler::{closure#0}
   8:     0x7f3560200dc9 - std[287527946f71f0bc]::sys::backtrace::__rust_end_short_backtrace::<std[287527946f71f0bc]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f356020bbdd - __rustc[5ec7081ce87b032f]::rust_begin_unwind
  10:     0x7f355cd0cfbc - core[7477a31a1a34cc49]::panicking::panic_fmt
  11:     0x7f3561235810 - <rustc_next_trait_solver[2bc6883c9be4be93]::solve::assembly::structural_traits::ReplaceProjectionWith<rustc_middle[725063e074f29df]::ty::context::TyCtxt, rustc_trait_selection[9fee51d8a10a777c]::solve::delegate::SolverDelegate> as rustc_type_ir[b93cf349b3a4f34d]::fold::FallibleTypeFolder<rustc_middle[725063e074f29df]::ty::context::TyCtxt>>::try_fold_ty
  12:     0x7f3561234ac8 - <&rustc_middle[725063e074f29df]::ty::list::RawList<(), rustc_middle[725063e074f29df]::ty::generic_args::GenericArg> as rustc_type_ir[b93cf349b3a4f34d]::fold::TypeFoldable<rustc_middle[725063e074f29df]::ty::context::TyCtxt>>::try_fold_with::<rustc_next_trait_solver[2bc6883c9be4be93]::solve::assembly::structural_traits::ReplaceProjectionWith<rustc_middle[725063e074f29df]::ty::context::TyCtxt, rustc_trait_selection[9fee51d8a10a777c]::solve::delegate::SolverDelegate>>
  13:     0x7f35619c9e80 - rustc_next_trait_solver[2bc6883c9be4be93]::solve::assembly::structural_traits::predicates_for_object_candidate::<rustc_trait_selection[9fee51d8a10a777c]::solve::delegate::SolverDelegate, rustc_middle[725063e074f29df]::ty::context::TyCtxt>
  14:     0x7f356172ee31 - <rustc_type_ir[b93cf349b3a4f34d]::predicate::TraitPredicate<rustc_middle[725063e074f29df]::ty::context::TyCtxt> as rustc_next_trait_solver[2bc6883c9be4be93]::solve::assembly::GoalKind<rustc_trait_selection[9fee51d8a10a777c]::solve::delegate::SolverDelegate, rustc_middle[725063e074f29df]::ty::context::TyCtxt>>::match_assumption::<<rustc_type_ir[b93cf349b3a4f34d]::predicate::TraitPredicate<rustc_middle[725063e074f29df]::ty::context::TyCtxt> as rustc_next_trait_solver[2bc6883c9be4be93]::solve::assembly::GoalKind<rustc_trait_selection[9fee51d8a10a777c]::solve::delegate::SolverDelegate, rustc_middle[725063e074f29df]::ty::context::TyCtxt>>::probe_and_consider_object_bound_candidate::{closure#0}>
  15:     0x7f356172e9b3 - <rustc_type_ir[b93cf349b3a4f34d]::predicate::TraitPredicate<rustc_middle[725063e074f29df]::ty::context::TyCtxt> as rustc_next_trait_solver[2bc6883c9be4be93]::solve::assembly::GoalKind<rustc_trait_selection[9fee51d8a10a777c]::solve::delegate::SolverDelegate, rustc_middle[725063e074f29df]::ty::context::TyCtxt>>::probe_and_consider_object_bound_candidate
  16:     0x7f3561729bbc - <rustc_next_trait_solver[2bc6883c9be4be93]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[9fee51d8a10a777c]::solve::delegate::SolverDelegate, rustc_middle[725063e074f29df]::ty::context::TyCtxt>>::compute_trait_goal
  17:     0x7f356141b74f - <rustc_next_trait_solver[2bc6883c9be4be93]::solve::search_graph::SearchGraphDelegate<rustc_trait_selection[9fee51d8a10a777c]::solve::delegate::SolverDelegate> as rustc_type_ir[b93cf349b3a4f34d]::search_graph::Delegate>::compute_goal::{closure#0}
  18:     0x7f35614323a3 - <rustc_next_trait_solver[2bc6883c9be4be93]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[9fee51d8a10a777c]::solve::delegate::SolverDelegate, rustc_middle[725063e074f29df]::ty::context::TyCtxt>>::evaluate_goal_raw
  19:     0x7f35614310dd - <rustc_infer[5a785d1c27494969]::infer::InferCtxt as rustc_trait_selection[9fee51d8a10a777c]::traits::query::evaluate_obligation::InferCtxtExt>::goal_may_hold_opaque_types_jank
  20:     0x7f3560fbff94 - <rustc_hir_typeck[ed5453188701a25b]::fn_ctxt::FnCtxt>::lookup_method_for_operator
  21:     0x7f3560c6327c - <rustc_hir_typeck[ed5453188701a25b]::fn_ctxt::FnCtxt>::try_overloaded_call_traits
  22:     0x7f3560c40dbc - <rustc_hir_typeck[ed5453188701a25b]::fn_ctxt::FnCtxt>::check_expr_call
  23:     0x7f3560c199b0 - <rustc_hir_typeck[ed5453188701a25b]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  24:     0x7f3560c14ac2 - <rustc_hir_typeck[ed5453188701a25b]::fn_ctxt::FnCtxt>::check_expr_block
  25:     0x7f3560c1998b - <rustc_hir_typeck[ed5453188701a25b]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:     0x7f3560bfa1a6 - rustc_hir_typeck[ed5453188701a25b]::check::check_fn
  27:     0x7f35615b3d33 - rustc_hir_typeck[ed5453188701a25b]::typeck_with_inspect::{closure#0}
  28:     0x7f35615b26b4 - rustc_query_impl[f20b8284200e680a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f20b8284200e680a]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[725063e074f29df]::query::erase::Erased<[u8; 8usize]>>
  29:     0x7f356095522a - rustc_query_system[b7e73caa2c2ad9a]::query::plumbing::try_execute_query::<rustc_query_impl[f20b8284200e680a]::DynamicConfig<rustc_data_structures[e0d8483206daafa2]::vec_cache::VecCache<rustc_span[851f35e07e3c2dd4]::def_id::LocalDefId, rustc_middle[725063e074f29df]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[b7e73caa2c2ad9a]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[f20b8284200e680a]::plumbing::QueryCtxt, false>
  30:     0x7f3560954b09 - rustc_query_impl[f20b8284200e680a]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7f356133fdb5 - <rustc_middle[725063e074f29df]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[1a80394817eddfdd]::check_crate::{closure#2}>::{closure#0}
  32:     0x7f356133f7c4 - rustc_hir_analysis[1a80394817eddfdd]::check_crate
  33:     0x7f35609493db - rustc_interface[5c48368f5debe80d]::passes::analysis
  34:     0x7f3560949035 - rustc_query_impl[f20b8284200e680a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f20b8284200e680a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[725063e074f29df]::query::erase::Erased<[u8; 0usize]>>
  35:     0x7f35619a4be3 - rustc_query_system[b7e73caa2c2ad9a]::query::plumbing::try_execute_query::<rustc_query_impl[f20b8284200e680a]::DynamicConfig<rustc_query_system[b7e73caa2c2ad9a]::query::caches::SingleCache<rustc_middle[725063e074f29df]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[f20b8284200e680a]::plumbing::QueryCtxt, false>
  36:     0x7f35619a49ce - rustc_query_impl[f20b8284200e680a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7f3561b82c11 - <rustc_interface[5c48368f5debe80d]::passes::create_and_enter_global_ctxt<core[7477a31a1a34cc49]::option::Option<rustc_interface[5c48368f5debe80d]::queries::Linker>, rustc_driver_impl[517260a07841a630]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[7477a31a1a34cc49]::ops::function::FnOnce<(&rustc_session[eb79e6d3104f29ae]::session::Session, rustc_middle[725063e074f29df]::ty::context::CurrentGcx, alloc[979041e9952e771b]::sync::Arc<rustc_data_structures[e0d8483206daafa2]::jobserver::Proxy>, &std[287527946f71f0bc]::sync::once_lock::OnceLock<rustc_middle[725063e074f29df]::ty::context::GlobalCtxt>, &rustc_data_structures[e0d8483206daafa2]::sync::worker_local::WorkerLocal<rustc_middle[725063e074f29df]::arena::Arena>, &rustc_data_structures[e0d8483206daafa2]::sync::worker_local::WorkerLocal<rustc_hir[7eac7792dedc1861]::Arena>, rustc_driver_impl[517260a07841a630]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  38:     0x7f35619f5d34 - rustc_interface[5c48368f5debe80d]::interface::run_compiler::<(), rustc_driver_impl[517260a07841a630]::run_compiler::{closure#0}>::{closure#1}
  39:     0x7f356195aa3a - std[287527946f71f0bc]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[5c48368f5debe80d]::util::run_in_thread_with_globals<rustc_interface[5c48368f5debe80d]::util::run_in_thread_pool_with_globals<rustc_interface[5c48368f5debe80d]::interface::run_compiler<(), rustc_driver_impl[517260a07841a630]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  40:     0x7f356195a7fe - <std[287527946f71f0bc]::thread::lifecycle::spawn_unchecked<rustc_interface[5c48368f5debe80d]::util::run_in_thread_with_globals<rustc_interface[5c48368f5debe80d]::util::run_in_thread_pool_with_globals<rustc_interface[5c48368f5debe80d]::interface::run_compiler<(), rustc_driver_impl[517260a07841a630]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[7477a31a1a34cc49]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7f356195c5c4 - <std[287527946f71f0bc]::sys::thread::unix::Thread>::new::thread_start
  42:     0x7f355b29698b - <unknown>
  43:     0x7f355b31a9cc - <unknown>
  44:                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.95.0-nightly (621d76794 2026-01-18) 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 `<impl at /tmp/icemaker_global_tempdir.P7n4BPAPG2qy/rustc_testrunner_tmpdir_reporting.Ihw4lR5RFRrV/mvce.rs:11:1: 11:34>::event`
#1 [analysis] running analysis passes on crate `mvce`
end of query stack
error[E0425]: cannot find function `any` in this scope
  --> /tmp/icemaker_global_tempdir.P7n4BPAPG2qy/rustc_testrunner_tmpdir_reporting.Ihw4lR5RFRrV/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.P7n4BPAPG2qy/rustc_testrunner_tmpdir_reporting.Ihw4lR5RFRrV/mvce.rs:13:32
   |
13 |         (self.callback)(any(), any());
   |                                ^^^ not found in this scope

error: aborting due to 5 previous errors

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

@rustbot label +WG-trait-system-refactor

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