Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: Unsize coercion, but &dyn Foo<'_> isn't coercible to &dyn Bar<'_, '_, ()> #131886

Open
matthiaskrgr opened this issue Oct 18, 2024 · 3 comments
Labels
-Zvalidate-mir Unstable option: MIR validation C-bug Category: This is a bug. F-trait_upcasting `#![feature(trait_upcasting)]` F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

#![feature(trait_upcasting, type_alias_impl_trait)]

type Tait = impl Sized;

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

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

original:

#![feature(trait_upcasting, 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<'_, '_, Tait>;
}

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

Version information

rustc 1.84.0-nightly (db8043bb1 2024-10-18)
binary: rustc
commit-hash: db8043bb199705e72246ca43d4af1e9dbe7d55be
commit-date: 2024-10-18
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zvalidate-mir --crate-type=lib

Program output

thread 'rustc' panicked at compiler/rustc_mir_transform/src/validate.rs:95:25:
broken MIR in Item(DefId(0:11 ~ mvce[0ba5]::test_correct3)) (after pass CheckPackedRef) at bb0[3]:
Unsize coercion, but `&dyn Foo<'_>` isn't coercible to `&dyn Bar<'_, '_, ()>`
stack backtrace:
   0:     0x78597e480c7a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h311c30006464a44d
   1:     0x78597ec03e0a - core::fmt::write::hefa9af5f84579548
   2:     0x78597ffa9291 - std::io::Write::write_fmt::h7b02b91c119616de
   3:     0x78597e480ad2 - std::sys::backtrace::BacktraceLock::print::h1bf9540f585b1c0c
   4:     0x78597e482fb6 - std::panicking::default_hook::{{closure}}::hdddf3b12f17177ae
   5:     0x78597e482e00 - std::panicking::default_hook::h95cfcd1ff904ee1d
   6:     0x78597d50280f - std[7ea95b089189ea8]::panicking::update_hook::<alloc[906de809b2d05e52]::boxed::Box<rustc_driver_impl[d25ecc56b0b66360]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x78597e4836c8 - std::panicking::rust_panic_with_hook::h4741b39194e01f78
   8:     0x78597e48349a - std::panicking::begin_panic_handler::{{closure}}::h99fdffb7c066d2c5
   9:     0x78597e481129 - std::sys::backtrace::__rust_end_short_backtrace::h2eb0b5ad24f0eada
  10:     0x78597e48315c - rust_begin_unwind
  11:     0x78597aee8c20 - core::panicking::panic_fmt::h9d32603254f24257
  12:     0x78597b703213 - <rustc_mir_transform[7bdd74c785fb8b70]::validate::CfgChecker>::fail::<alloc[906de809b2d05e52]::string::String>
  13:     0x78597b701615 - <rustc_mir_transform[7bdd74c785fb8b70]::validate::Validator as rustc_mir_transform[7bdd74c785fb8b70]::pass_manager::MirPass>::run_pass
  14:     0x78597cde1a10 - rustc_mir_transform[7bdd74c785fb8b70]::pass_manager::validate_body
  15:     0x78597ec06d29 - rustc_mir_transform[7bdd74c785fb8b70]::mir_built
  16:     0x78597ec06907 - rustc_query_impl[32db4d22f0b27131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[32db4d22f0b27131]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 8usize]>>
  17:     0x78597ef68d7a - rustc_query_system[4eccca7fcaf3aaf0]::query::plumbing::try_execute_query::<rustc_query_impl[32db4d22f0b27131]::DynamicConfig<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::VecCache<rustc_span[1759084578182824]::def_id::LocalDefId, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[32db4d22f0b27131]::plumbing::QueryCtxt, false>
  18:     0x78597ef6888d - rustc_query_impl[32db4d22f0b27131]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  19:     0x78597ec2c929 - rustc_mir_transform[7bdd74c785fb8b70]::ffi_unwind_calls::has_ffi_unwind_calls
  20:     0x78597ec2c2d5 - rustc_query_impl[32db4d22f0b27131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[32db4d22f0b27131]::query_impl::has_ffi_unwind_calls::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 1usize]>>
  21:     0x78597efbd167 - rustc_query_system[4eccca7fcaf3aaf0]::query::plumbing::try_execute_query::<rustc_query_impl[32db4d22f0b27131]::DynamicConfig<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::VecCache<rustc_span[1759084578182824]::def_id::LocalDefId, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[32db4d22f0b27131]::plumbing::QueryCtxt, false>
  22:     0x78597efbcd41 - rustc_query_impl[32db4d22f0b27131]::query_impl::has_ffi_unwind_calls::get_query_non_incr::__rust_end_short_backtrace
  23:     0x78597c0a075f - rustc_mir_transform[7bdd74c785fb8b70]::mir_promoted
  24:     0x78597f0e2292 - rustc_query_impl[32db4d22f0b27131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[32db4d22f0b27131]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 16usize]>>
  25:     0x78597f0e255a - rustc_query_system[4eccca7fcaf3aaf0]::query::plumbing::try_execute_query::<rustc_query_impl[32db4d22f0b27131]::DynamicConfig<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::VecCache<rustc_span[1759084578182824]::def_id::LocalDefId, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[32db4d22f0b27131]::plumbing::QueryCtxt, false>
  26:     0x78597fc2d9d0 - rustc_query_impl[32db4d22f0b27131]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace
  27:     0x78597fc2dac3 - rustc_query_impl[32db4d22f0b27131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[32db4d22f0b27131]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 8usize]>>
  28:     0x78597ef68d7a - rustc_query_system[4eccca7fcaf3aaf0]::query::plumbing::try_execute_query::<rustc_query_impl[32db4d22f0b27131]::DynamicConfig<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::VecCache<rustc_span[1759084578182824]::def_id::LocalDefId, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[32db4d22f0b27131]::plumbing::QueryCtxt, false>
  29:     0x78597ef687d3 - rustc_query_impl[32db4d22f0b27131]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  30:     0x78597f5c32f9 - rustc_middle[3555d1292876aeec]::query::plumbing::query_get_at::<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::VecCache<rustc_span[1759084578182824]::def_id::LocalDefId, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 8usize]>>>
  31:     0x78597d6fc2d2 - <rustc_hir_analysis[3f1e84bf7d1c6f50]::collect::type_of::opaque::TaitConstraintLocator>::check
  32:     0x78597d69a8b2 - <rustc_hir_analysis[3f1e84bf7d1c6f50]::collect::type_of::opaque::TaitConstraintLocator as rustc_hir[5cb3b32afa60e663]::intravisit::Visitor>::visit_nested_item
  33:     0x78597fcca3b7 - rustc_hir_analysis[3f1e84bf7d1c6f50]::collect::type_of::type_of_opaque
  34:     0x78597fcc9ce5 - rustc_query_impl[32db4d22f0b27131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[32db4d22f0b27131]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 8usize]>>
  35:     0x78597ec2972a - rustc_query_system[4eccca7fcaf3aaf0]::query::plumbing::try_execute_query::<rustc_query_impl[32db4d22f0b27131]::DynamicConfig<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::DefIdCache<rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[32db4d22f0b27131]::plumbing::QueryCtxt, false>
  36:     0x78597fe49bb6 - rustc_query_impl[32db4d22f0b27131]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
  37:     0x78597f3be502 - rustc_middle[3555d1292876aeec]::query::plumbing::query_get_at::<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::DefIdCache<rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 8usize]>>>
  38:     0x78597bda2135 - rustc_hir_analysis[3f1e84bf7d1c6f50]::collect::type_of::type_of
  39:     0x78597ec2aa30 - rustc_query_impl[32db4d22f0b27131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[32db4d22f0b27131]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 8usize]>>
  40:     0x78597ec2972a - rustc_query_system[4eccca7fcaf3aaf0]::query::plumbing::try_execute_query::<rustc_query_impl[32db4d22f0b27131]::DynamicConfig<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::DefIdCache<rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[32db4d22f0b27131]::plumbing::QueryCtxt, false>
  41:     0x78597ec292e3 - rustc_query_impl[32db4d22f0b27131]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  42:     0x78597f3be502 - rustc_middle[3555d1292876aeec]::query::plumbing::query_get_at::<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::DefIdCache<rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 8usize]>>>
  43:     0x78597fcd57d9 - rustc_hir_analysis[3f1e84bf7d1c6f50]::check::check::check_item_type
  44:     0x78597bba12ed - rustc_hir_analysis[3f1e84bf7d1c6f50]::check::wfcheck::check_well_formed
  45:     0x78597efbdac7 - rustc_query_impl[32db4d22f0b27131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[32db4d22f0b27131]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 1usize]>>
  46:     0x78597efbd21f - rustc_query_system[4eccca7fcaf3aaf0]::query::plumbing::try_execute_query::<rustc_query_impl[32db4d22f0b27131]::DynamicConfig<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::VecCache<rustc_span[1759084578182824]::def_id::LocalDefId, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[32db4d22f0b27131]::plumbing::QueryCtxt, false>
  47:     0x78597efbce90 - rustc_query_impl[32db4d22f0b27131]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  48:     0x78597efbdb47 - rustc_middle[3555d1292876aeec]::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::VecCache<rustc_span[1759084578182824]::def_id::LocalDefId, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 1usize]>>, ()>
  49:     0x78597efbe11b - rustc_hir_analysis[3f1e84bf7d1c6f50]::check::wfcheck::check_mod_type_wf
  50:     0x78597efbdb6f - rustc_query_impl[32db4d22f0b27131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[32db4d22f0b27131]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 1usize]>>
  51:     0x78597f74533b - rustc_query_system[4eccca7fcaf3aaf0]::query::plumbing::try_execute_query::<rustc_query_impl[32db4d22f0b27131]::DynamicConfig<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::DefaultCache<rustc_span[1759084578182824]::def_id::LocalModDefId, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[32db4d22f0b27131]::plumbing::QueryCtxt, false>
  52:     0x78597f7450ed - rustc_query_impl[32db4d22f0b27131]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  53:     0x78597ef648bb - rustc_hir_analysis[3f1e84bf7d1c6f50]::check_crate
  54:     0x78597f519f57 - rustc_interface[ca54b24fb50a6540]::passes::run_required_analyses
  55:     0x78597face5de - rustc_interface[ca54b24fb50a6540]::passes::analysis
  56:     0x78597face5b1 - rustc_query_impl[32db4d22f0b27131]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[32db4d22f0b27131]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 1usize]>>
  57:     0x78597fb7a56e - rustc_query_system[4eccca7fcaf3aaf0]::query::plumbing::try_execute_query::<rustc_query_impl[32db4d22f0b27131]::DynamicConfig<rustc_query_system[4eccca7fcaf3aaf0]::query::caches::SingleCache<rustc_middle[3555d1292876aeec]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[32db4d22f0b27131]::plumbing::QueryCtxt, false>
  58:     0x78597fb7a24f - rustc_query_impl[32db4d22f0b27131]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  59:     0x78597fa0e91e - rustc_interface[ca54b24fb50a6540]::interface::run_compiler::<core[8e2925c99194b988]::result::Result<(), rustc_span[1759084578182824]::ErrorGuaranteed>, rustc_driver_impl[d25ecc56b0b66360]::run_compiler::{closure#0}>::{closure#1}
  60:     0x78597faab714 - std[7ea95b089189ea8]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[ca54b24fb50a6540]::util::run_in_thread_with_globals<rustc_interface[ca54b24fb50a6540]::util::run_in_thread_pool_with_globals<rustc_interface[ca54b24fb50a6540]::interface::run_compiler<core[8e2925c99194b988]::result::Result<(), rustc_span[1759084578182824]::ErrorGuaranteed>, rustc_driver_impl[d25ecc56b0b66360]::run_compiler::{closure#0}>::{closure#1}, core[8e2925c99194b988]::result::Result<(), rustc_span[1759084578182824]::ErrorGuaranteed>>::{closure#0}, core[8e2925c99194b988]::result::Result<(), rustc_span[1759084578182824]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[8e2925c99194b988]::result::Result<(), rustc_span[1759084578182824]::ErrorGuaranteed>>
  61:     0x78597faabb28 - <<std[7ea95b089189ea8]::thread::Builder>::spawn_unchecked_<rustc_interface[ca54b24fb50a6540]::util::run_in_thread_with_globals<rustc_interface[ca54b24fb50a6540]::util::run_in_thread_pool_with_globals<rustc_interface[ca54b24fb50a6540]::interface::run_compiler<core[8e2925c99194b988]::result::Result<(), rustc_span[1759084578182824]::ErrorGuaranteed>, rustc_driver_impl[d25ecc56b0b66360]::run_compiler::{closure#0}>::{closure#1}, core[8e2925c99194b988]::result::Result<(), rustc_span[1759084578182824]::ErrorGuaranteed>>::{closure#0}, core[8e2925c99194b988]::result::Result<(), rustc_span[1759084578182824]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[8e2925c99194b988]::result::Result<(), rustc_span[1759084578182824]::ErrorGuaranteed>>::{closure#1} as core[8e2925c99194b988]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  62:     0x78597faac5eb - std::sys::pal::unix::thread::Thread::new::thread_start::hfa6ba0429166ab6d
  63:     0x78598132939d - <unknown>
  64:     0x7859813ae49c - <unknown>
  65:                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.84.0-nightly (db8043bb1 2024-10-18) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z validate-mir --crate-type lib -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
end of query stack

@rustbot label +F-trait_upcasting +F-type_alias_impl_trait

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 18, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-trait_upcasting `#![feature(trait_upcasting)]` F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` labels Oct 18, 2024
@fmease fmease added -Zvalidate-mir Unstable option: MIR validation and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 18, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Oct 20, 2024
@WaffleLapkin
Copy link
Member

The lifetimes are unnecessary, this also fails when using -Zvalidate-mir:

#![feature(trait_upcasting, type_alias_impl_trait)]

type Tait = impl Sized;

trait Foo: Bar<Tait> {}
trait Bar<T> {}

fn test_correct3(x: &dyn Foo, _: Tait) {
    _ = x as &dyn Bar<()>;
}

Specifically the problem seems to be with using the hidden type in upcasting, when an opaque is expected.

@crlf0710
Copy link
Member

Tried all three code snippets on playground:

Build using the Nightly version: 1.85.0-nightly

(2024-12-09 a224f3807e58afc93535)

None of the snippets ICEs.

Might worth adding some (or all) of them to test suites.

@WaffleLapkin
Copy link
Member

@crlf0710 they only ICE with -Zvalidate-mir, which you can't enable on playground as far as I know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Zvalidate-mir Unstable option: MIR validation C-bug Category: This is a bug. F-trait_upcasting `#![feature(trait_upcasting)]` F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants