Skip to content

[ICE]: equating two type variables, both of which have known types #154189

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

trait ToUnit<'a> {
    type Unit;
}
impl ToUnit<'_> for *const u32 {}
trait Overlap<T> {}
type Assoc<'a, T> = <*const T as ToUnit<'a>>::Unit;
impl<T> Overlap<T> for T {}
impl<'a, T> Overlap<(&'a (), Assoc<'a, T>)> for T {}

original:

#![feature(unboxed_closures)]
trait ToUnit<'a> {
    type Unit;
}
impl ToUnit<'_> for *const u32 {
    type Unit = ();
}
trait Overlap<T> {}
type Assoc<'a, T> = <*const T as ToUnit<'a>>::Unit;
impl<T> Overlap<T> for T {}
impl<'a, T> Overlap<(&'a (), Assoc<'a, T>)> for T {}
fn main() {}

Version information

rustc 1.96.0-nightly (20f19f461 2026-03-21)
binary: rustc
commit-hash: 20f19f4615200b16e3631816e7824e832ff394db
commit-date: 2026-03-21
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.0

Possibly related line of code:

fn unify_values(value1: &Self, value2: &Self) -> Result<Self, ut::NoError> {
match (value1, value2) {
// We never equate two type variables, both of which
// have known types. Instead, we recursively equate
// those types.
(&TypeVariableValue::Known { .. }, &TypeVariableValue::Known { .. }) => {
bug!("equating two type variables, both of which have known types")
}
// If one side is known, prefer that one.
(&TypeVariableValue::Known { .. }, &TypeVariableValue::Unknown { .. }) => Ok(*value1),
(&TypeVariableValue::Unknown { .. }, &TypeVariableValue::Known { .. }) => Ok(*value2),

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.DOlDtl0fcDJm/rustc_testrunner_tmpdir_reporting.lwUYV1McQ3Xx/mvce.rs:8:53
  |
8 | impl<'a, T> Overlap<(&'a (), Assoc<'a, T>)> for T {}
  |                                                     ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.DOlDtl0fcDJm/rustc_testrunner_tmpdir_reporting.lwUYV1McQ3Xx/mvce.rs`

error[E0046]: not all trait items implemented, missing: `Unit`
 --> /tmp/icemaker_global_tempdir.DOlDtl0fcDJm/rustc_testrunner_tmpdir_reporting.lwUYV1McQ3Xx/mvce.rs:4:1
  |
2 |     type Unit;
  |     --------- `Unit` from trait
3 | }
4 | impl ToUnit<'_> for *const u32 {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Unit` in implementation

error: internal compiler error: /rustc-dev/20f19f4615200b16e3631816e7824e832ff394db/compiler/rustc_infer/src/infer/type_variable.rs:388:17: equating two type variables, both of which have known types


thread 'rustc' (2487414) panicked at /rustc-dev/20f19f4615200b16e3631816e7824e832ff394db/compiler/rustc_infer/src/infer/type_variable.rs:388:17:
Box<dyn Any>
stack backtrace:
   0:     0x7fa4dd7af54b - <<std[6be7b9c9e62b267e]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[9c1c5d34ae8b3de6]::fmt::Display>::fmt
   1:     0x7fa4dde2f248 - core[9c1c5d34ae8b3de6]::fmt::write
   2:     0x7fa4dd7c6556 - <std[6be7b9c9e62b267e]::sys::stdio::unix::Stderr as std[6be7b9c9e62b267e]::io::Write>::write_fmt
   3:     0x7fa4dd785558 - std[6be7b9c9e62b267e]::panicking::default_hook::{closure#0}
   4:     0x7fa4dd7a2953 - std[6be7b9c9e62b267e]::panicking::default_hook
   5:     0x7fa4dc799e4c - std[6be7b9c9e62b267e]::panicking::update_hook::<alloc[5ace279b6dd5471b]::boxed::Box<rustc_driver_impl[1e93a328f0ffcd34]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fa4dd7a2c32 - std[6be7b9c9e62b267e]::panicking::panic_with_hook
   7:     0x7fa4dc7c9b71 - std[6be7b9c9e62b267e]::panicking::begin_panic::<rustc_errors[261c5e0a20cc1b6f]::ExplicitBug>::{closure#0}
   8:     0x7fa4dc7c2856 - std[6be7b9c9e62b267e]::sys::backtrace::__rust_end_short_backtrace::<std[6be7b9c9e62b267e]::panicking::begin_panic<rustc_errors[261c5e0a20cc1b6f]::ExplicitBug>::{closure#0}, !>
   9:     0x7fa4dc7c0488 - std[6be7b9c9e62b267e]::panicking::begin_panic::<rustc_errors[261c5e0a20cc1b6f]::ExplicitBug>
  10:     0x7fa4dc7d51e1 - <rustc_errors[261c5e0a20cc1b6f]::diagnostic::BugAbort as rustc_errors[261c5e0a20cc1b6f]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7fa4dcdb4799 - rustc_middle[dc03b2c5cfb92cd3]::util::bug::opt_span_bug_fmt::<rustc_span[6746bc40c6a7ede4]::span_encoding::Span>::{closure#0}
  12:     0x7fa4dcdb4922 - rustc_middle[dc03b2c5cfb92cd3]::ty::context::tls::with_opt::<rustc_middle[dc03b2c5cfb92cd3]::util::bug::opt_span_bug_fmt<rustc_span[6746bc40c6a7ede4]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7fa4dcda53fb - rustc_middle[dc03b2c5cfb92cd3]::ty::context::tls::with_context_opt::<rustc_middle[dc03b2c5cfb92cd3]::ty::context::tls::with_opt<rustc_middle[dc03b2c5cfb92cd3]::util::bug::opt_span_bug_fmt<rustc_span[6746bc40c6a7ede4]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7fa4da4f5384 - rustc_middle[dc03b2c5cfb92cd3]::util::bug::bug_fmt
  15:     0x7fa4deb29a3b - <rustc_infer[f8fbf9ca85ffe13e]::infer::InferCtxt>::instantiate_ty_var::<rustc_type_ir[58b14473ebcbd56]::relate::solver_relating::SolverRelating<rustc_infer[f8fbf9ca85ffe13e]::infer::InferCtxt, rustc_middle[dc03b2c5cfb92cd3]::ty::context::TyCtxt>>
  16:     0x7fa4deb29dd8 - <rustc_type_ir[58b14473ebcbd56]::relate::solver_relating::SolverRelating<rustc_infer[f8fbf9ca85ffe13e]::infer::InferCtxt, rustc_middle[dc03b2c5cfb92cd3]::ty::context::TyCtxt> as rustc_type_ir[58b14473ebcbd56]::relate::TypeRelation<rustc_middle[dc03b2c5cfb92cd3]::ty::context::TyCtxt>>::tys
  17:     0x7fa4deb2c2f7 - <core[9c1c5d34ae8b3de6]::result::Result<rustc_middle[dc03b2c5cfb92cd3]::ty::generic_args::GenericArg, rustc_type_ir[58b14473ebcbd56]::error::TypeError<rustc_middle[dc03b2c5cfb92cd3]::ty::context::TyCtxt>> as rustc_type_ir[58b14473ebcbd56]::interner::CollectAndApply<rustc_middle[dc03b2c5cfb92cd3]::ty::generic_args::GenericArg, &rustc_middle[dc03b2c5cfb92cd3]::ty::list::RawList<(), rustc_middle[dc03b2c5cfb92cd3]::ty::generic_args::GenericArg>>>::collect_and_apply::<core[9c1c5d34ae8b3de6]::iter::adapters::map::Map<core[9c1c5d34ae8b3de6]::iter::adapters::zip::Zip<core[9c1c5d34ae8b3de6]::iter::adapters::copied::Copied<core[9c1c5d34ae8b3de6]::slice::iter::Iter<rustc_middle[dc03b2c5cfb92cd3]::ty::generic_args::GenericArg>>, core[9c1c5d34ae8b3de6]::iter::adapters::copied::Copied<core[9c1c5d34ae8b3de6]::slice::iter::Iter<rustc_middle[dc03b2c5cfb92cd3]::ty::generic_args::GenericArg>>>, rustc_type_ir[58b14473ebcbd56]::relate::relate_args_invariantly<rustc_middle[dc03b2c5cfb92cd3]::ty::context::TyCtxt, rustc_type_ir[58b14473ebcbd56]::relate::solver_relating::SolverRelating<rustc_infer[f8fbf9ca85ffe13e]::infer::InferCtxt, rustc_middle[dc03b2c5cfb92cd3]::ty::context::TyCtxt>>::{closure#0}>, <rustc_middle[dc03b2c5cfb92cd3]::ty::context::TyCtxt>::mk_args_from_iter<core[9c1c5d34ae8b3de6]::iter::adapters::map::Map<core[9c1c5d34ae8b3de6]::iter::adapters::zip::Zip<core[9c1c5d34ae8b3de6]::iter::adapters::copied::Copied<core[9c1c5d34ae8b3de6]::slice::iter::Iter<rustc_middle[dc03b2c5cfb92cd3]::ty::generic_args::GenericArg>>, core[9c1c5d34ae8b3de6]::iter::adapters::copied::Copied<core[9c1c5d34ae8b3de6]::slice::iter::Iter<rustc_middle[dc03b2c5cfb92cd3]::ty::generic_args::GenericArg>>>, rustc_type_ir[58b14473ebcbd56]::relate::relate_args_invariantly<rustc_middle[dc03b2c5cfb92cd3]::ty::context::TyCtxt, rustc_type_ir[58b14473ebcbd56]::relate::solver_relating::SolverRelating<rustc_infer[f8fbf9ca85ffe13e]::infer::InferCtxt, rustc_middle[dc03b2c5cfb92cd3]::ty::context::TyCtxt>>::{closure#0}>, core[9c1c5d34ae8b3de6]::result::Result<rustc_middle[dc03b2c5cfb92cd3]::ty::generic_args::GenericArg, rustc_type_ir[58b14473ebcbd56]::error::TypeError<rustc_middle[dc03b2c5cfb92cd3]::ty::context::TyCtxt>>>::{closure#0}>
  18:     0x7fa4dde6d1f2 - <rustc_infer[f8fbf9ca85ffe13e]::infer::at::At>::eq_trace::<rustc_type_ir[58b14473ebcbd56]::predicate::TraitRef<rustc_middle[dc03b2c5cfb92cd3]::ty::context::TyCtxt>>
  19:     0x7fa4de80c2d4 - rustc_trait_selection[674756819060e284]::traits::coherence::overlap
  20:     0x7fa4db13d197 - <rustc_middle[dc03b2c5cfb92cd3]::traits::specialization_graph::Children as rustc_trait_selection[674756819060e284]::traits::specialize::specialization_graph::ChildrenExt>::insert
  21:     0x7fa4dedb677b - <rustc_middle[dc03b2c5cfb92cd3]::traits::specialization_graph::Graph as rustc_trait_selection[674756819060e284]::traits::specialize::specialization_graph::GraphExt>::insert
  22:     0x7fa4dde4b634 - rustc_trait_selection[674756819060e284]::traits::specialize::specialization_graph_provider
  23:     0x7fa4dde4f14d - rustc_query_impl[ff9c83ade533030f]::execution::try_execute_query::<rustc_middle[dc03b2c5cfb92cd3]::query::caches::DefIdCache<rustc_middle[dc03b2c5cfb92cd3]::query::erase::ErasedData<[u8; 8usize]>>, false>
  24:     0x7fa4ddf38e24 - rustc_query_impl[ff9c83ade533030f]::query_impl::specialization_graph_of::execute_query_non_incr::__rust_end_short_backtrace
  25:     0x7fa4ddf3c547 - rustc_hir_analysis[54a62f91511e91de]::coherence::coherent_trait
  26:     0x7fa4ddf3c25f - rustc_query_impl[ff9c83ade533030f]::query_impl::coherent_trait::invoke_provider_fn::__rust_begin_short_backtrace
  27:     0x7fa4de293bec - rustc_query_impl[ff9c83ade533030f]::execution::try_execute_query::<rustc_middle[dc03b2c5cfb92cd3]::query::caches::DefIdCache<rustc_middle[dc03b2c5cfb92cd3]::query::erase::ErasedData<[u8; 1usize]>>, false>
  28:     0x7fa4de292d40 - rustc_query_impl[ff9c83ade533030f]::query_impl::coherent_trait::execute_query_non_incr::__rust_end_short_backtrace
  29:     0x7fa4de4ce1ae - rustc_hir_analysis[54a62f91511e91de]::check::check::check_item_type
  30:     0x7fa4de4cc66a - rustc_hir_analysis[54a62f91511e91de]::check::wfcheck::check_well_formed
  31:     0x7fa4de4cc64b - rustc_query_impl[ff9c83ade533030f]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  32:     0x7fa4de4cbc70 - rustc_query_impl[ff9c83ade533030f]::execution::try_execute_query::<rustc_data_structures[45bb070fb52fceb8]::vec_cache::VecCache<rustc_span[6746bc40c6a7ede4]::def_id::LocalDefId, rustc_middle[dc03b2c5cfb92cd3]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[dc03b2c5cfb92cd3]::dep_graph::graph::DepNodeIndex>, false>
  33:     0x7fa4de4cba07 - rustc_query_impl[ff9c83ade533030f]::query_impl::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
  34:     0x7fa4de4c81b3 - rustc_hir_analysis[54a62f91511e91de]::check::wfcheck::check_type_wf
  35:     0x7fa4de4c80af - rustc_query_impl[ff9c83ade533030f]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  36:     0x7fa4df041c10 - rustc_query_impl[ff9c83ade533030f]::execution::try_execute_query::<rustc_middle[dc03b2c5cfb92cd3]::query::caches::SingleCache<rustc_middle[dc03b2c5cfb92cd3]::query::erase::ErasedData<[u8; 1usize]>>, false>
  37:     0x7fa4df0419e9 - rustc_query_impl[ff9c83ade533030f]::query_impl::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
  38:     0x7fa4de6a9917 - rustc_hir_analysis[54a62f91511e91de]::check_crate
  39:     0x7fa4ddee539a - rustc_interface[dbd43765a67ece38]::passes::analysis
  40:     0x7fa4df044389 - rustc_query_impl[ff9c83ade533030f]::execution::try_execute_query::<rustc_middle[dc03b2c5cfb92cd3]::query::caches::SingleCache<rustc_middle[dc03b2c5cfb92cd3]::query::erase::ErasedData<[u8; 0usize]>>, false>
  41:     0x7fa4df043ff5 - rustc_query_impl[ff9c83ade533030f]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  42:     0x7fa4df013e54 - rustc_interface[dbd43765a67ece38]::interface::run_compiler::<(), rustc_driver_impl[1e93a328f0ffcd34]::run_compiler::{closure#0}>::{closure#1}
  43:     0x7fa4deffeafe - std[6be7b9c9e62b267e]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[dbd43765a67ece38]::util::run_in_thread_with_globals<rustc_interface[dbd43765a67ece38]::util::run_in_thread_pool_with_globals<rustc_interface[dbd43765a67ece38]::interface::run_compiler<(), rustc_driver_impl[1e93a328f0ffcd34]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  44:     0x7fa4defff3a0 - <std[6be7b9c9e62b267e]::thread::lifecycle::spawn_unchecked<rustc_interface[dbd43765a67ece38]::util::run_in_thread_with_globals<rustc_interface[dbd43765a67ece38]::util::run_in_thread_pool_with_globals<rustc_interface[dbd43765a67ece38]::interface::run_compiler<(), rustc_driver_impl[1e93a328f0ffcd34]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[9c1c5d34ae8b3de6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:     0x7fa4df00022c - <std[6be7b9c9e62b267e]::sys::thread::unix::Thread>::new::thread_start
  46:     0x7fa4d8aa597a - <unknown>
  47:     0x7fa4d8b292bc - <unknown>
  48:                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.96.0-nightly (20f19f461 2026-03-21) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [specialization_graph_of] building specialization graph of trait `Overlap`
#1 [coherent_trait] coherence checking all impls of trait `Overlap`
#2 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.DOlDtl0fcDJm/rustc_testrunner_tmpdir_reporting.lwUYV1McQ3Xx/mvce.rs:7:1: 7:25>` is well-formed
#3 [check_type_wf] checking that types are well-formed
#4 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 3 previous errors

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

@rustbot label +F-unboxed_closures

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-unboxed_closures`#![feature(unboxed_closures)]`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.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