Skip to content

[].map: failure to relate an opaque to itself should result in an error later on #149162

@Philipp-M

Description

@Philipp-M

I just have encountered this issue with Xilem, I've tried to minimize it.

Code

// Cargo.toml
// [dependencies]
// xilem   = { git = "https://github.com/linebender/xilem.git", rev = "c44e94b6139f794268a23355b525985ab597db98" }
use xilem::{WidgetView, core::Edit, view::text_button};

fn buttons() -> [impl WidgetView<Edit<()>> + use<>; 9] {
    [0, 1, 2, 3, 4, 5, 6, 7, 8].map(|_| text_button("", |_: &mut ()| {}))
}

// Also happens to something like this:
pub fn buttons() -> Vec<impl WidgetView<Edit<()>> + use<>> {
    (0..9).map(|_| text_button("", |_: &mut ()| {})).collect()
}

Meta

rustc --version --verbose:

rustc 1.93.0-nightly (07bdbaedc 2025-11-19)

Error output

   Compiling ice-repro v0.1.0 (/home/philm/dev/personal/rust/xilem/xilem/ice-repro)
note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: failure to relate an opaque to itself should result in an error later on
 --> ice-repro/src/lib.rs:4:37
  |
4 |     [0, 1, 2, 3, 4, 5, 6, 7, 8].map(|_| text_button("", |_: &mut ()| {}))
  |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: delayed at compiler/rustc_borrowck/src/type_check/relate_tys.rs:359:37 - disabled backtrace
 --> ice-repro/src/lib.rs:4:37
  |
4 |     [0, 1, 2, 3, 4, 5, 6, 7, 8].map(|_| text_button("", |_: &mut ()| {}))
  |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: failure to relate an opaque to itself should result in an error later on
 --> ice-repro/src/lib.rs:4:40
  |
4 |     [0, 1, 2, 3, 4, 5, 6, 7, 8].map(|_| text_button("", |_: &mut ()| {}))
  |                                        ^
  |
note: delayed at compiler/rustc_borrowck/src/type_check/relate_tys.rs:359:37 - disabled backtrace
 --> ice-repro/src/lib.rs:4:40
  |
4 |     [0, 1, 2, 3, 4, 5, 6, 7, 8].map(|_| text_button("", |_: &mut ()| {}))
  |                                        ^
Backtrace

delayed bug: failure to relate an opaque to itself should result in an error later on
   0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
   1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
   2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
   4: <rustc_middle::ty::generic_args::GenericArg as rustc_type_ir::relate::Relate<rustc_middle::ty::context::TyCtxt>>::relate::<rustc_borrowck::type_check::relate_tys::NllTypeRelating>
   5: rustc_type_ir::relate::relate_args_with_variances::<rustc_middle::ty::context::TyCtxt, rustc_borrowck::type_check::relate_tys::NllTypeRelating>
   6: rustc_type_ir::relate::structurally_relate_tys::<rustc_middle::ty::context::TyCtxt, rustc_borrowck::type_check::relate_tys::NllTypeRelating>::{closure#0}
   7: <rustc_borrowck::type_check::relate_tys::NllTypeRelating as rustc_type_ir::relate::TypeRelation<rustc_middle::ty::context::TyCtxt>>::tys
   8: <rustc_type_ir::ty_kind::FnSig<rustc_middle::ty::context::TyCtxt> as rustc_type_ir::relate::Relate<rustc_middle::ty::context::TyCtxt>>::relate::<rustc_borrowck::type_check::relate_tys::NllTypeRelating>
   9: rustc_type_ir::relate::structurally_relate_tys::<rustc_middle::ty::context::TyCtxt, rustc_borrowck::type_check::relate_tys::NllTypeRelating>::{closure#0}
  10: <rustc_middle::ty::generic_args::GenericArg as rustc_type_ir::relate::Relate<rustc_middle::ty::context::TyCtxt>>::relate::<rustc_borrowck::type_check::relate_tys::NllTypeRelating>
  11: <core::result::Result<rustc_middle::ty::generic_args::GenericArg, rustc_type_ir::error::TypeError<rustc_middle::ty::context::TyCtxt>> as rustc_type_ir::interner::CollectAndApply<rustc_middle::ty::generic_args::GenericArg, &rustc_middle::ty::list::RawList<(), rustc_middle::ty::generic_args::GenericArg>>>::collect_and_apply::<core::iter::adapters::map::Map<core::iter::adapters::zip::Zip<core::iter::adapters::copied::Copied<core::slice::iter::Iter<rustc_middle::ty::generic_args::GenericArg>>, core::iter::adapters::copied::Copied<core::slice::iter::Iter<rustc_middle::ty::generic_args::GenericArg>>>, rustc_type_ir::relate::relate_args_invariantly<rustc_middle::ty::context::TyCtxt, rustc_borrowck::type_check::relate_tys::NllTypeRelating>::{closure#0}>, <rustc_middle::ty::context::TyCtxt>::mk_args_from_iter<core::iter::adapters::map::Map<core::iter::adapters::zip::Zip<core::iter::adapters::copied::Copied<core::slice::iter::Iter<rustc_middle::ty::generic_args::GenericArg>>, core::iter::adapters::copied::Copied<core::slice::iter::Iter<rustc_middle::ty::generic_args::GenericArg>>>, rustc_type_ir::relate::relate_args_invariantly<rustc_middle::ty::context::TyCtxt, rustc_borrowck::type_check::relate_tys::NllTypeRelating>::{closure#0}>, core::result::Result<rustc_middle::ty::generic_args::GenericArg, rustc_type_ir::error::TypeError<rustc_middle::ty::context::TyCtxt>>>::{closure#0}>
  12: rustc_type_ir::relate::structurally_relate_tys::<rustc_middle::ty::context::TyCtxt, rustc_borrowck::type_check::relate_tys::NllTypeRelating>::{closure#0}
  13: rustc_type_ir::relate::structurally_relate_tys::<rustc_middle::ty::context::TyCtxt, rustc_borrowck::type_check::relate_tys::NllTypeRelating>::{closure#0}
  14: rustc_borrowck::type_check::type_check
  15: <rustc_borrowck::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
  16: rustc_borrowck::mir_borrowck
  17: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
  18: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  19: rustc_query_impl::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
  20: rustc_hir_analysis::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit
  21: rustc_hir_analysis::collect::type_of::type_of_opaque
  22: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
  23: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  24: rustc_query_impl::query_impl::type_of_opaque::get_query_incr::__rust_end_short_backtrace
  25: rustc_hir_analysis::collect::type_of::type_of
  26: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
  27: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  28: rustc_query_impl::query_impl::type_of::get_query_incr::__rust_end_short_backtrace
  29: rustc_hir_analysis::check::check::check_opaque
  30: rustc_hir_analysis::check::check::check_item_type
  31: rustc_hir_analysis::check::wfcheck::check_well_formed
  32: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
  33: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 1]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  34: rustc_query_impl::query_impl::check_well_formed::get_query_incr::__rust_end_short_backtrace
  35: rustc_hir_analysis::check::wfcheck::check_type_wf
  36: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
  37: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  38: rustc_query_impl::query_impl::check_type_wf::get_query_incr::__rust_end_short_backtrace
  39: rustc_hir_analysis::check_crate
  40: rustc_interface::passes::analysis
  41: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
  42: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  43: rustc_query_impl::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  44: <rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  45: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
  46: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  47: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  48: std::sys::thread::unix::Thread::new::thread_start
  49: start_thread
  50: __GI___clone3

delayed bug: failure to relate an opaque to itself should result in an error later on
   0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
   1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
   2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
   4: <rustc_middle::ty::generic_args::GenericArg as rustc_type_ir::relate::Relate<rustc_middle::ty::context::TyCtxt>>::relate::<rustc_borrowck::type_check::relate_tys::NllTypeRelating>
   5: rustc_type_ir::relate::relate_args_with_variances::<rustc_middle::ty::context::TyCtxt, rustc_borrowck::type_check::relate_tys::NllTypeRelating>
   6: rustc_type_ir::relate::structurally_relate_tys::<rustc_middle::ty::context::TyCtxt, rustc_borrowck::type_check::relate_tys::NllTypeRelating>::{closure#0}
   7: rustc_borrowck::type_check::type_check
   8: <rustc_borrowck::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
   9: rustc_borrowck::mir_borrowck
  10: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
  11: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  12: rustc_query_impl::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
  13: rustc_hir_analysis::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit
  14: rustc_hir_analysis::collect::type_of::type_of_opaque
  15: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
  16: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  17: rustc_query_impl::query_impl::type_of_opaque::get_query_incr::__rust_end_short_backtrace
  18: rustc_hir_analysis::collect::type_of::type_of
  19: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
  20: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  21: rustc_query_impl::query_impl::type_of::get_query_incr::__rust_end_short_backtrace
  22: rustc_hir_analysis::check::check::check_opaque
  23: rustc_hir_analysis::check::check::check_item_type
  24: rustc_hir_analysis::check::wfcheck::check_well_formed
  25: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
  26: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 1]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  27: rustc_query_impl::query_impl::check_well_formed::get_query_incr::__rust_end_short_backtrace
  28: rustc_hir_analysis::check::wfcheck::check_type_wf
  29: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
  30: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  31: rustc_query_impl::query_impl::check_type_wf::get_query_incr::__rust_end_short_backtrace
  32: rustc_hir_analysis::check_crate
  33: rustc_interface::passes::analysis
  34: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
  35: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  36: rustc_query_impl::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  37: <rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  38: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
  39: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  40: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41: std::sys::thread::unix::Thread::new::thread_start
  42: start_thread
  43: __GI___clone3



rustc version: 1.93.0-nightly (07bdbaedc 2025-11-19)
platform: x86_64-unknown-linux-gnu

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions