Skip to content

ICE with (only) coerce_unsized in find_vtable_types_for_unsizing #139812

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

Closed
Zenithsiz opened this issue Apr 14, 2025 · 0 comments · Fixed by #139818
Closed

ICE with (only) coerce_unsized in find_vtable_types_for_unsizing #139812

Zenithsiz opened this issue Apr 14, 2025 · 0 comments · Fixed by #139818
Assignees
Labels
C-bug Category: This is a bug. F-coerce_unsized The `CoerceUnsized` trait 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.

Comments

@Zenithsiz
Copy link

Code

#![feature(coerce_unsized)]

use std::any::Any;
use std::ops::CoerceUnsized;

trait RcFamily {
    type Rc<T: ?Sized>;
}
struct R;
impl RcFamily for R {
    type Rc<T: ?Sized> = std::rc::Rc<T>;
}

// ICEs
type Rc<T> = <R as RcFamily>::Rc<T>;

// Does not ICE
//type Rc<T> = std::rc::Rc<T>;

struct Signal<T: ?Sized>(Rc<T>);
impl CoerceUnsized<Signal<dyn Any>> for Signal<i32> {}

fn main() {
    Signal(Rc::new(5_i32)) as Signal<dyn Any>;
}

Playground

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (0fe8f3454 2025-04-10)
binary: rustc
commit-hash: 0fe8f3454dbe9dda52a254991347e96bec579a6f
commit-date: 2025-04-10
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Error output

error: internal compiler error: compiler/rustc_monomorphize/src/collector.rs:1093:14: find_vtable_types_for_unsizing: invalid coercion Alias(Projection, AliasTy { args: [R, i32], def_id: DefId(0:6 ~ test[48ef]::RcFamily::Rc), .. }) -> Alias(Projection, AliasTy { args: [R, dyn [Binder { value: Trait(std::any::Any), bound_vars: [] }] + '{erased}], def_id: DefId(0:6 ~ test[48ef]::RcFamily::Rc), .. })


thread 'rustc' panicked at compiler/rustc_monomorphize/src/collector.rs:1093:14:
Box<dyn Any>
stack backtrace:
   0:     0x7f90c1ca3003 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h7686682c5480ba78
   1:     0x7f90c2406091 - core::fmt::write::hf1e231fde889384f
   2:     0x7f90c3818b51 - std::io::Write::write_fmt::hcc89e08516f58cda
   3:     0x7f90c1ca2e62 - std::sys::backtrace::BacktraceLock::print::hc42ae0f3d83336fc
   4:     0x7f90c1ca694a - std::panicking::default_hook::{{closure}}::hf08c95cde50909c9
   5:     0x7f90c1ca64cf - std::panicking::default_hook::h857accdf112ffe33
   6:     0x7f90c0d00c43 - std[5a4a45264b2b22b8]::panicking::update_hook::<alloc[b673e4f92a898af7]::boxed::Box<rustc_driver_impl[e5eb260dc8961db4]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7f90c1ca71c3 - std::panicking::rust_panic_with_hook::ha8b882f4d13e028f
   8:     0x7f90c0d3f981 - std[5a4a45264b2b22b8]::panicking::begin_panic::<rustc_errors[97cfdff8159a699f]::ExplicitBug>::{closure#0}
   9:     0x7f90c0d33896 - std[5a4a45264b2b22b8]::sys::backtrace::__rust_end_short_backtrace::<std[5a4a45264b2b22b8]::panicking::begin_panic<rustc_errors[97cfdff8159a699f]::ExplicitBug>::{closure#0}, !>
  10:     0x7f90c0d300d9 - std[5a4a45264b2b22b8]::panicking::begin_panic::<rustc_errors[97cfdff8159a699f]::ExplicitBug>
  11:     0x7f90c0d49d51 - <rustc_errors[97cfdff8159a699f]::diagnostic::BugAbort as rustc_errors[97cfdff8159a699f]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7f90c139dfba - rustc_middle[c35ac5c4e9820b71]::util::bug::opt_span_bug_fmt::<rustc_span[5498c1e576460479]::span_encoding::Span>::{closure#0}
  13:     0x7f90c1378e9a - rustc_middle[c35ac5c4e9820b71]::ty::context::tls::with_opt::<rustc_middle[c35ac5c4e9820b71]::util::bug::opt_span_bug_fmt<rustc_span[5498c1e576460479]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7f90c1378d0b - rustc_middle[c35ac5c4e9820b71]::ty::context::tls::with_context_opt::<rustc_middle[c35ac5c4e9820b71]::ty::context::tls::with_opt<rustc_middle[c35ac5c4e9820b71]::util::bug::opt_span_bug_fmt<rustc_span[5498c1e576460479]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7f90be6867b0 - rustc_middle[c35ac5c4e9820b71]::util::bug::bug_fmt
  16:     0x7f90c3e40814 - rustc_monomorphize[3e638de941efb25f]::collector::find_vtable_types_for_unsizing.cold
  17:     0x7f90c39ab456 - rustc_monomorphize[3e638de941efb25f]::collector::find_vtable_types_for_unsizing.warm
  18:     0x7f90bf3ddb8f - rustc_monomorphize[3e638de941efb25f]::collector::items_of_instance
  19:     0x7f90c2ec82b2 - rustc_query_impl[cda7d84f80c9103c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cda7d84f80c9103c]::query_impl::items_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c35ac5c4e9820b71]::query::erase::Erased<[u8; 32usize]>>
  20:     0x7f90c2ec8614 - rustc_query_system[6b3ea517af74fad7]::query::plumbing::try_execute_query::<rustc_query_impl[cda7d84f80c9103c]::DynamicConfig<rustc_query_system[6b3ea517af74fad7]::query::caches::DefaultCache<(rustc_middle[c35ac5c4e9820b71]::ty::instance::Instance, rustc_middle[c35ac5c4e9820b71]::mir::mono::CollectionMode), rustc_middle[c35ac5c4e9820b71]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[cda7d84f80c9103c]::plumbing::QueryCtxt, false>
  21:     0x7f90c2ec822b - rustc_query_impl[cda7d84f80c9103c]::query_impl::items_of_instance::get_query_non_incr::__rust_end_short_backtrace
  22:     0x7f90c2ec9d30 - rustc_monomorphize[3e638de941efb25f]::collector::collect_items_rec::{closure#0}
  23:     0x7f90c2ecac2c - rustc_monomorphize[3e638de941efb25f]::collector::collect_items_rec
  24:     0x7f90c2ed19e8 - rustc_monomorphize[3e638de941efb25f]::partitioning::collect_and_partition_mono_items
  25:     0x7f90c2ed15a4 - rustc_query_impl[cda7d84f80c9103c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cda7d84f80c9103c]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c35ac5c4e9820b71]::query::erase::Erased<[u8; 40usize]>>
  26:     0x7f90c2ed1589 - <rustc_query_impl[cda7d84f80c9103c]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[56f6e271b4871ecd]::ops::function::FnOnce<(rustc_middle[c35ac5c4e9820b71]::ty::context::TyCtxt, ())>>::call_once
  27:     0x7f90c2ed75b4 - rustc_query_system[6b3ea517af74fad7]::query::plumbing::try_execute_query::<rustc_query_impl[cda7d84f80c9103c]::DynamicConfig<rustc_query_system[6b3ea517af74fad7]::query::caches::SingleCache<rustc_middle[c35ac5c4e9820b71]::query::erase::Erased<[u8; 40usize]>>, false, false, false>, rustc_query_impl[cda7d84f80c9103c]::plumbing::QueryCtxt, false>
  28:     0x7f90c2ed7344 - rustc_query_impl[cda7d84f80c9103c]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7f90c3622627 - <rustc_codegen_llvm[7e8954d3ae8f9fa2]::LlvmCodegenBackend as rustc_codegen_ssa[244d404b982eb0b8]::traits::backend::CodegenBackend>::codegen_crate
  30:     0x7f90c360e69d - <rustc_interface[c746d0abdacc4b70]::queries::Linker>::codegen_and_build_linker
  31:     0x7f90c360c22c - rustc_interface[c746d0abdacc4b70]::passes::create_and_enter_global_ctxt::<core[56f6e271b4871ecd]::option::Option<rustc_interface[c746d0abdacc4b70]::queries::Linker>, rustc_driver_impl[e5eb260dc8961db4]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  32:     0x7f90c3558db9 - rustc_interface[c746d0abdacc4b70]::interface::run_compiler::<(), rustc_driver_impl[e5eb260dc8961db4]::run_compiler::{closure#0}>::{closure#1}
  33:     0x7f90c352c88f - std[5a4a45264b2b22b8]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c746d0abdacc4b70]::util::run_in_thread_with_globals<rustc_interface[c746d0abdacc4b70]::util::run_in_thread_pool_with_globals<rustc_interface[c746d0abdacc4b70]::interface::run_compiler<(), rustc_driver_impl[e5eb260dc8961db4]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  34:     0x7f90c352d16b - <<std[5a4a45264b2b22b8]::thread::Builder>::spawn_unchecked_<rustc_interface[c746d0abdacc4b70]::util::run_in_thread_with_globals<rustc_interface[c746d0abdacc4b70]::util::run_in_thread_pool_with_globals<rustc_interface[c746d0abdacc4b70]::interface::run_compiler<(), rustc_driver_impl[e5eb260dc8961db4]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[56f6e271b4871ecd]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  35:     0x7f90c352e56b - std::sys::pal::unix::thread::Thread::new::thread_start::h0924f76e10405c90
  36:     0x7f90bd2a370a - <unknown>
  37:     0x7f90bd327aac - <unknown>
  38:                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: please attach the file at `/tmp/rustc-ice-2025-04-14T15_52_16-261430.txt` to your bug report

query stack during panic:
#0 [items_of_instance] collecting items used by `main`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to 1 previous error
Backtrace

error: internal compiler error: compiler/rustc_monomorphize/src/collector.rs:1093:14: find_vtable_types_for_unsizing: invalid coercion Alias(Projection, AliasTy { args: [R, i32], def_id: DefId(0:6 ~ test[48ef]::RcFamily::Rc), .. }) -> Alias(Projection, AliasTy { args: [R, dyn [Binder { value: Trait(std::any::Any), bound_vars: [] }] + '{erased}], def_id: DefId(0:6 ~ test[48ef]::RcFamily::Rc), .. })


thread 'rustc' panicked at compiler/rustc_monomorphize/src/collector.rs:1093:14:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: rustc_monomorphize::collector::find_vtable_types_for_unsizing.cold
   7: rustc_monomorphize::collector::find_vtable_types_for_unsizing.warm
   8: rustc_monomorphize::collector::items_of_instance
      [... omitted 1 frame ...]
   9: rustc_monomorphize::collector::collect_items_rec::{closure#0}
  10: rustc_monomorphize::collector::collect_items_rec
  11: rustc_monomorphize::partitioning::collect_and_partition_mono_items
      [... omitted 2 frames ...]
  12: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  13: <rustc_interface::queries::Linker>::codegen_and_build_linker
  14: 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}::{closure#0}
  15: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: please attach the file at `/tmp/rustc-ice-2025-04-14T15_50_25-261287.txt` to your bug report

query stack during panic:
#0 [items_of_instance] collecting items used by `main`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to 1 previous error

This is similar to #74451, but it seems that one requires specialization, while this one ICEs with just coerce_unsized.

rustc-ice-2025-04-14T15_52_16-261430.txt

@Zenithsiz Zenithsiz 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 Apr 14, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 14, 2025
@compiler-errors compiler-errors self-assigned this Apr 14, 2025
@jieyouxu jieyouxu added F-coerce_unsized The `CoerceUnsized` trait and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 15, 2025
Zalathar added a commit to Zalathar/rust that referenced this issue Apr 15, 2025
…=oli-obk

Normalize ADT field in `find_tails_for_unsizing`

See the comment inline and in the test.

TL;DR is that we're getting getting a type from a `type_of` query and then matching on it structurally in codegen, so we're obligated to normalize it. The fact that this wasn't triggered earlier is that all of the types that have `CoerceUnsized` implementations never encounter aliases when peeling the ADT down to their base reference/ptr type.

**NOTE**: I also renamed some things and reorganized the function a bit.

Fixes rust-lang#139812
Fixes rust-lang#74451, which I didn't think was interesting enough to add another test.

r? oli-obk
@bors bors closed this as completed in 27f1f4d Apr 15, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 15, 2025
Rollup merge of rust-lang#139818 - compiler-errors:normalize-tails, r=oli-obk

Normalize ADT field in `find_tails_for_unsizing`

See the comment inline and in the test.

TL;DR is that we're getting getting a type from a `type_of` query and then matching on it structurally in codegen, so we're obligated to normalize it. The fact that this wasn't triggered earlier is that all of the types that have `CoerceUnsized` implementations never encounter aliases when peeling the ADT down to their base reference/ptr type.

**NOTE**: I also renamed some things and reorganized the function a bit.

Fixes rust-lang#139812
Fixes rust-lang#74451, which I didn't think was interesting enough to add another test.

r? oli-obk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-coerce_unsized The `CoerceUnsized` trait 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants