Skip to content

ICE when coercing a too large array to a trait object #152030

@theemathas

Description

@theemathas

Code

#![feature(try_as_dyn)]

trait Trait {}
impl Trait for [u8; 1<<63] {}

pub fn foo(x: &[u8; 1<<63]) {
    let _ = std::any::try_as_dyn::<[u8; 1<<63], dyn Trait>(x);
}

Tracking issue for try_as_dyn: #144361

Meta

Reproducible on the playground with version 1.95.0-nightly (2026-02-02 f60a0f1bcc5a2a6dd8eb)

Error output

thread 'rustc' (61) panicked at /rustc-dev/f60a0f1bcc5a2a6dd8eb2d2021da79b40f5fbae9/compiler/rustc_middle/src/ty/vtable.rs:104:10:
failed to build vtable representation: SizeOverflow([u8; 9223372036854775808_usize])
Backtrace

stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: rustc_middle::ty::vtable::vtable_allocation_provider
      [... omitted 2 frames ...]
   4: rustc_monomorphize::collector::collect_alloc
   5: rustc_monomorphize::collector::items_of_instance
      [... omitted 1 frame ...]
   6: rustc_monomorphize::collector::collect_items_rec
   7: rustc_monomorphize::collector::collect_items_rec
   8: rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}
   9: rustc_monomorphize::partitioning::collect_and_partition_mono_items
      [... omitted 2 frames ...]
  10: rustc_codegen_ssa::back::symbol_export::exported_generic_symbols_provider_local
      [... omitted 2 frames ...]
  11: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
  12: <rustc_metadata::rmeta::encoder::encode_metadata::{closure#3} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, &std::path::Path)>>::call_once
  13: rustc_metadata::rmeta::encoder::encode_metadata
  14: rustc_metadata::fs::encode_and_write_metadata
  15: <rustc_interface::queries::Linker>::codegen_and_build_linker
  16: <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}
  17: 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.

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: please attach the file at `/playground/rustc-ice-2026-02-03T08_23_40-59.txt` to your bug report

note: rustc 1.95.0-nightly (f60a0f1bc 2026-02-02) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [vtable_allocation] vtable const allocation for <[u8; ValTree(Leaf(0x8000000000000000): usize)] as Trait>
#1 [items_of_instance] collecting items used by `core::any::try_as_dyn::<[u8; ValTree(Leaf(0x8000000000000000): usize)], dyn Trait>`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
#3 [exported_generic_symbols] collecting exported generic symbols for crate `0`
end of query stack

Metadata

Metadata

Assignees

Labels

A-dyn-traitArea: trait objects, vtable layoutA-layoutArea: Memory layout of typesC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions