rust-lang / rust-lang/rust

ICE: broken mir: Unsize coercion .. isn't coercible

Open
#148,094 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

-Zvalidate-mir C-bug F-type_alias_impl_trait I-ICE S-bug-has-test S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

similar to https://github.com/rust-lang/rust/issues/131886 but unlike https://github.com/rust-lang/rust/issues/131886 still crashing

auto-reduced (treereduce-rust):

//@compile-flags: -Zvalidate-mir
#![feature(type_alias_impl_trait)]

type Tait = impl Sized;

trait Foo<'a>: Bar<'a, 'a, Tait> {}
trait Bar<'a, 'b, T> {}

#[define_opaque(Tait)]
fn test_correct3<'a>(x: &dyn Foo<'a>, _: Tait) {
    let _ = x as &dyn Bar<'_, 'a, ()>;
}

fn main() {}

original:

#![feature(type_alias_impl_trait)]

//@ check-pass

type Tait = impl Sized;

trait Foo<'a>: Bar<'a, 'a, Tait> {}
trait Bar<'a, 'b, T> {}

fn test_correct(x: &dyn Foo<'static>) {
    let _ = x as &dyn Bar<'static, 'static, Tait>;
}

fn test_correct2<'a>(x: &dyn Foo<'a>) {
    let _ = x as &dyn Bar<'_, 'static, Tait>;
}

#[define_opaque(Tait)]
fn test_correct3<'a>(x: &dyn Foo<'a>, _: Tait) {
    let _ = x as &dyn Bar<'_, 'a, ()>;
}

fn main() {}

Version information

rustc 1.92.0-nightly (f43597208 2025-10-24)
binary: rustc
commit-hash: f435972085b697a1ece8ee6a1ac76efff8d1df7b
commit-date: 2025-10-24
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.3

Possibly related line of code:
https://github.com/rust-lang/rust/blob/f435972085b697a1ece8ee6a1ac76efff8d1df7b/compiler/rustc_mir_transform/src/validate.rs#L75-L87

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zvalidate-mir

Program output

error: internal compiler error: compiler/rustc_mir_transform/src/validate.rs:81:25: broken MIR in Item(DefId(0:12 ~ mvce[1b4a]::test_correct3)) (after pass CheckForceInline) at bb0[3]:
                                Unsize coercion, but `&dyn Foo<'_>` isn't coercible to `&dyn Bar<'_, '_, ()>`
  --> /tmp/icemaker_global_tempdir.20BLeJTxFmM8/rustc_testrunner_tmpdir_reporting.PuUQz2zg7lg7/mvce.rs:10:13
   |
10 |     let _ = x as &dyn Bar<'_, 'a, ()>;
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^


thread 'rustc' (4016117) panicked at compiler/rustc_mir_transform/src/validate.rs:81:25:
Box<dyn Any>
stack backtrace:
   0:     0x7fc571834073 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h492c738ad49cea7d
   1:     0x7fc572001b98 - core::fmt::write::h1c21b4db123ae31c
   2:     0x7fc5717e8403 - std::io::Write::write_fmt::h78003e47d8f6c72e
   3:     0x7fc5717f9bf2 - std::sys::backtrace::BacktraceLock::print::h0d646c4d1cbf366e
   4:     0x7fc5717ffcc9 - std::panicking::default_hook::{{closure}}::h274ab31bbd3c2851
   5:     0x7fc5717ff7f3 - std::panicking::default_hook::he590f8320f1e009e
   6:     0x7fc570800611 - std[3e186dc2068ac4b9]::panicking::update_hook::<alloc[47fc8f5871530046]::boxed::Box<rustc_driver_impl[b652d2bf07caa0d8]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7fc5718000ef - std::panicking::panic_with_hook::hc0910476a8aaf08a
   8:     0x7fc570839e61 - std[3e186dc2068ac4b9]::panicking::begin_panic::<rustc_errors[345ffcadd731d51f]::ExplicitBug>::{closure#0}
   9:     0x7fc57082e056 - std[3e186dc2068ac4b9]::sys::backtrace::__rust_end_short_backtrace::<std[3e186dc2068ac4b9]::panicking::begin_panic<rustc_errors[345ffcadd731d51f]::ExplicitBug>::{closure#0}, !>
  10:     0x7fc57082b939 - std[3e186dc2068ac4b9]::panicking::begin_panic::<rustc_errors[345ffcadd731d51f]::ExplicitBug>
  11:     0x7fc5708459d1 - <rustc_errors[345ffcadd731d51f]::diagnostic::BugAbort as rustc_errors[345ffcadd731d51f]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7fc570db9f8c - <rustc_errors[345ffcadd731d51f]::DiagCtxtHandle>::span_bug::<rustc_span[b6aef8613cdfc213]::span_encoding::Span, alloc[47fc8f5871530046]::string::String>
  13:     0x7fc570ddd4c7 - rustc_middle[df80570e3f8f0476]::util::bug::opt_span_bug_fmt::<rustc_span[b6aef8613cdfc213]::span_encoding::Span>::{closure#0}
  14:     0x7fc570ddd7ca - rustc_middle[df80570e3f8f0476]::ty::context::tls::with_opt::<rustc_middle[df80570e3f8f0476]::util::bug::opt_span_bug_fmt<rustc_span[b6aef8613cdfc213]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x7fc570dce53b - rustc_middle[df80570e3f8f0476]::ty::context::tls::with_context_opt::<rustc_middle[df80570e3f8f0476]::ty::context::tls::with_opt<rustc_middle[df80570e3f8f0476]::util::bug::opt_span_bug_fmt<rustc_span[b6aef8613cdfc213]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x7fc56e643b47 - rustc_middle[df80570e3f8f0476]::util::bug::span_bug_fmt::<rustc_span[b6aef8613cdfc213]::span_encoding::Span>
  17:     0x7fc56f640cdc - <rustc_mir_transform[bbe91f48e8a67098]::validate::CfgChecker>::fail::<alloc[47fc8f5871530046]::string::String>
  18:     0x7fc5732d38c4 - <rustc_mir_transform[bbe91f48e8a67098]::validate::Validator as rustc_mir_transform[bbe91f48e8a67098]::pass_manager::MirPass>::run_pass
  19:     0x7fc56f66a2a5 - rustc_mir_transform[bbe91f48e8a67098]::pass_manager::validate_body
  20:     0x7fc57200786b - rustc_query_impl[ce892b7de41d33cc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ce892b7de41d33cc]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 8usize]>>
  21:     0x7fc572ad6177 - rustc_query_system[c36681704e76fc2e]::query::plumbing::try_execute_query::<rustc_query_impl[ce892b7de41d33cc]::DynamicConfig<rustc_data_structures[9e234764dc4c351e]::vec_cache::VecCache<rustc_span[b6aef8613cdfc213]::def_id::LocalDefId, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[c36681704e76fc2e]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[ce892b7de41d33cc]::plumbing::QueryCtxt, false>
  22:     0x7fc572ad5bc9 - rustc_query_impl[ce892b7de41d33cc]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7fc57202d372 - rustc_mir_transform[bbe91f48e8a67098]::ffi_unwind_calls::has_ffi_unwind_calls
  24:     0x7fc57202cd59 - rustc_query_impl[ce892b7de41d33cc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ce892b7de41d33cc]::query_impl::has_ffi_unwind_calls::dynamic_query::{closure#2}::{closure#0}, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 1usize]>>
  25:     0x7fc57299ff2f - rustc_query_system[c36681704e76fc2e]::query::plumbing::try_execute_query::<rustc_query_impl[ce892b7de41d33cc]::DynamicConfig<rustc_data_structures[9e234764dc4c351e]::vec_cache::VecCache<rustc_span[b6aef8613cdfc213]::def_id::LocalDefId, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[c36681704e76fc2e]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[ce892b7de41d33cc]::plumbing::QueryCtxt, false>
  26:     0x7fc57299fbfd - rustc_query_impl[ce892b7de41d33cc]::query_impl::has_ffi_unwind_calls::get_query_non_incr::__rust_end_short_backtrace
  27:     0x7fc56f61eb47 - rustc_mir_transform[bbe91f48e8a67098]::mir_promoted
  28:     0x7fc5729faf52 - rustc_query_impl[ce892b7de41d33cc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ce892b7de41d33cc]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 16usize]>>
  29:     0x7fc5729fb215 - rustc_query_system[c36681704e76fc2e]::query::plumbing::try_execute_query::<rustc_query_impl[ce892b7de41d33cc]::DynamicConfig<rustc_data_structures[9e234764dc4c351e]::vec_cache::VecCache<rustc_span[b6aef8613cdfc213]::def_id::LocalDefId, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 16usize]>, rustc_query_system[c36681704e76fc2e]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[ce892b7de41d33cc]::plumbing::QueryCtxt, false>
  30:     0x7fc5729fada2 - rustc_query_impl[ce892b7de41d33cc]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7fc573176923 - rustc_borrowck[9c9a4d4a4caa4bbc]::mir_borrowck
  32:     0x7fc5731767d9 - rustc_query_impl[ce892b7de41d33cc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ce892b7de41d33cc]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 8usize]>>
  33:     0x7fc572ad6177 - rustc_query_system[c36681704e76fc2e]::query::plumbing::try_execute_query::<rustc_query_impl[ce892b7de41d33cc]::DynamicConfig<rustc_data_structures[9e234764dc4c351e]::vec_cache::VecCache<rustc_span[b6aef8613cdfc213]::def_id::LocalDefId, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[c36681704e76fc2e]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[ce892b7de41d33cc]::plumbing::QueryCtxt, false>
  34:     0x7fc572ad4289 - rustc_query_impl[ce892b7de41d33cc]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7fc57097b174 - <rustc_hir_analysis[83592e86f71d95cd]::collect::type_of::opaque::TaitConstraintLocator>::check
  36:     0x7fc5709b79e0 - rustc_hir_analysis[83592e86f71d95cd]::collect::type_of::opaque::find_opaque_ty_constraints_for_tait
  37:     0x7fc573f0c409 - rustc_hir_analysis[83592e86f71d95cd]::collect::type_of::type_of_opaque.cold
  38:     0x7fc573086507 - rustc_query_impl[ce892b7de41d33cc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ce892b7de41d33cc]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 8usize]>>
  39:     0x7fc57201b2c6 - rustc_query_system[c36681704e76fc2e]::query::plumbing::try_execute_query::<rustc_query_impl[ce892b7de41d33cc]::DynamicConfig<rustc_query_system[c36681704e76fc2e]::query::caches::DefIdCache<rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[ce892b7de41d33cc]::plumbing::QueryCtxt, false>
  40:     0x7fc5731cc065 - rustc_query_impl[ce892b7de41d33cc]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7fc5728c7477 - rustc_hir_analysis[83592e86f71d95cd]::collect::type_of::type_of
  42:     0x7fc57201c626 - rustc_query_impl[ce892b7de41d33cc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ce892b7de41d33cc]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 8usize]>>
  43:     0x7fc57201b2c6 - rustc_query_system[c36681704e76fc2e]::query::plumbing::try_execute_query::<rustc_query_impl[ce892b7de41d33cc]::DynamicConfig<rustc_query_system[c36681704e76fc2e]::query::caches::DefIdCache<rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[ce892b7de41d33cc]::plumbing::QueryCtxt, false>
  44:     0x7fc57201ae6f - rustc_query_impl[ce892b7de41d33cc]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7fc573086f6c - rustc_hir_analysis[83592e86f71d95cd]::check::check::check_opaque
  46:     0x7fc5729a9449 - rustc_hir_analysis[83592e86f71d95cd]::check::check::check_item_type
  47:     0x7fc5729a093a - rustc_hir_analysis[83592e86f71d95cd]::check::wfcheck::check_well_formed
  48:     0x7fc5729a091b - rustc_query_impl[ce892b7de41d33cc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ce892b7de41d33cc]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 1usize]>>
  49:     0x7fc5729a0192 - rustc_query_system[c36681704e76fc2e]::query::plumbing::try_execute_query::<rustc_query_impl[ce892b7de41d33cc]::DynamicConfig<rustc_data_structures[9e234764dc4c351e]::vec_cache::VecCache<rustc_span[b6aef8613cdfc213]::def_id::LocalDefId, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[c36681704e76fc2e]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[ce892b7de41d33cc]::plumbing::QueryCtxt, false>
  50:     0x7fc57299fc96 - rustc_query_impl[ce892b7de41d33cc]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  51:     0x7fc57299d3d1 - rustc_hir_analysis[83592e86f71d95cd]::check::wfcheck::check_type_wf
  52:     0x7fc57299d265 - rustc_query_impl[ce892b7de41d33cc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ce892b7de41d33cc]::query_impl::check_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 1usize]>>
  53:     0x7fc5730c6dd4 - rustc_query_system[c36681704e76fc2e]::query::plumbing::try_execute_query::<rustc_query_impl[ce892b7de41d33cc]::DynamicConfig<rustc_query_system[c36681704e76fc2e]::query::caches::SingleCache<rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[ce892b7de41d33cc]::plumbing::QueryCtxt, false>
  54:     0x7fc5730c6bb6 - rustc_query_impl[ce892b7de41d33cc]::query_impl::check_type_wf::get_query_non_incr::__rust_end_short_backtrace
  55:     0x7fc572aa507a - rustc_hir_analysis[83592e86f71d95cd]::check_crate
  56:     0x7fc572acf770 - rustc_interface[10f842ee2745836b]::passes::analysis
  57:     0x7fc572acf435 - rustc_query_impl[ce892b7de41d33cc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ce892b7de41d33cc]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 0usize]>>
  58:     0x7fc5730cd726 - rustc_query_system[c36681704e76fc2e]::query::plumbing::try_execute_query::<rustc_query_impl[ce892b7de41d33cc]::DynamicConfig<rustc_query_system[c36681704e76fc2e]::query::caches::SingleCache<rustc_middle[df80570e3f8f0476]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[ce892b7de41d33cc]::plumbing::QueryCtxt, false>
  59:     0x7fc5730cd37c - rustc_query_impl[ce892b7de41d33cc]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  60:     0x7fc57333ec8a - <rustc_interface[10f842ee2745836b]::passes::create_and_enter_global_ctxt<core[e8997f4232dfd718]::option::Option<rustc_interface[10f842ee2745836b]::queries::Linker>, rustc_driver_impl[b652d2bf07caa0d8]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[e8997f4232dfd718]::ops::function::FnOnce<(&rustc_session[4dec040bcdb04b8e]::session::Session, rustc_middle[df80570e3f8f0476]::ty::context::CurrentGcx, alloc[47fc8f5871530046]::sync::Arc<rustc_data_structures[9e234764dc4c351e]::jobserver::Proxy>, &std[3e186dc2068ac4b9]::sync::once_lock::OnceLock<rustc_middle[df80570e3f8f0476]::ty::context::GlobalCtxt>, &rustc_data_structures[9e234764dc4c351e]::sync::worker_local::WorkerLocal<rustc_middle[df80570e3f8f0476]::arena::Arena>, &rustc_data_structures[9e234764dc4c351e]::sync::worker_local::WorkerLocal<rustc_hir[739a0293ab2ba12c]::Arena>, rustc_driver_impl[b652d2bf07caa0d8]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  61:     0x7fc5731b37e2 - rustc_interface[10f842ee2745836b]::interface::run_compiler::<(), rustc_driver_impl[b652d2bf07caa0d8]::run_compiler::{closure#0}>::{closure#1}
  62:     0x7fc572dc09c0 - std[3e186dc2068ac4b9]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[10f842ee2745836b]::util::run_in_thread_with_globals<rustc_interface[10f842ee2745836b]::util::run_in_thread_pool_with_globals<rustc_interface[10f842ee2745836b]::interface::run_compiler<(), rustc_driver_impl[b652d2bf07caa0d8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  63:     0x7fc572dc06a4 - <<std[3e186dc2068ac4b9]::thread::Builder>::spawn_unchecked_<rustc_interface[10f842ee2745836b]::util::run_in_thread_with_globals<rustc_interface[10f842ee2745836b]::util::run_in_thread_pool_with_globals<rustc_interface[10f842ee2745836b]::interface::run_compiler<(), rustc_driver_impl[b652d2bf07caa0d8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[e8997f4232dfd718]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  64:     0x7fc572dbf02f - std::sys::thread::unix::Thread::new::thread_start::h69c86f976e686da7
  65:     0x7fc56c8969cb - <unknown>
  66:     0x7fc56c91aa0c - <unknown>
  67:                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.92.0-nightly (f43597208 2025-10-24) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z validate-mir -Z dump-mir-dir=dir

query stack during panic:
#0 [mir_built] building MIR for `test_correct3`
#1 [has_ffi_unwind_calls] checking if `test_correct3` contains FFI-unwind calls
#2 [mir_promoted] promoting constants in MIR for `test_correct3`
#3 [mir_borrowck] borrow-checking `test_correct3`
#4 [type_of_opaque] computing type of opaque `Tait::{opaque#0}`
#5 [type_of] computing type of `Tait::{opaque#0}`
#6 [check_well_formed] checking that `Tait::{opaque#0}` is well-formed
#7 [check_type_wf] checking that types are well-formed
#8 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error


@rustbot label +F-type_alias_impl_trait +-Zvalidate-mir

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reduced example with rustc and -Zvalidate-mir, then inspect compiler/rustc_mir_transform/src/validate.rs:75-87, especially the validation of the unsize coercion. Compare the behavior with issues #131886 and the original MIR output. Done means this example no longer produces an internal compiler error or compiler panic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.