Skip to content

Reflection TypeId::trait_info_of#152003

Open
9SonSteroids wants to merge 4 commits intorust-lang:mainfrom
9SonSteroids:trait_info_of
Open

Reflection TypeId::trait_info_of#152003
9SonSteroids wants to merge 4 commits intorust-lang:mainfrom
9SonSteroids:trait_info_of

Conversation

@9SonSteroids
Copy link

@9SonSteroids 9SonSteroids commented Feb 2, 2026

This is for #146922.

As #151236 was requested to be remade by someone I implemented the functionality as TypeId::trait_info_of which additionally allows getting the vtable pointer to build dyn Objects in recursive reflection.

It allows checking if a TypeId implements a trait. Since this is my first PR feel free to tell me if there are any formal issues.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 2, 2026
@9SonSteroids 9SonSteroids marked this pull request as ready for review February 2, 2026 16:32
@rustbot
Copy link
Collaborator

rustbot commented Feb 2, 2026

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

The reflection data structures are tied exactly to the implementation
in the compiler. Make sure to also adjust rustc_const_eval/src/const_eval/type_info.rs

cc @oli-obk

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 2, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 2, 2026

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@9SonSteroids 9SonSteroids changed the title Trait info of Reflection TypeId::trait_info_of Feb 2, 2026
@SpriteOvO SpriteOvO added the F-type_info #![feature(type_info)] label Feb 2, 2026
@izagawd izagawd mentioned this pull request Feb 2, 2026
4 tasks
@coolcatcoder
Copy link

Lovely, great job!

@theemathas
Copy link
Contributor

The documentation of DynMetadata says:

It is possible to name this struct with a type parameter that is not a dyn trait object (for example DynMetadata<u64>) but not to obtain a meaningful value of that struct.

The trait_info_of_trait_type_id produces a TraitImpl<*const ()>, which can be used to produce a DynMetadata<*const ()>, violating this documentation. Is this a problem?

@rust-log-analyzer

This comment has been minimized.

@theemathas
Copy link
Contributor

Trying to create a vtable for a DST results in an ICE with this PR.

#![feature(type_info)]

use std::any::TypeId;

trait Trait {}
impl Trait for [i32] {}

fn main() {
    const { TypeId::of::<[i32]>().trait_info_of_trait_type_id(TypeId::of::<dyn Trait>()) };
}
Error output
thread 'rustc' (77522) panicked at compiler/rustc_middle/src/ty/vtable.rs:105:5:
can't create a vtable for an unsized type
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:689:5
   1: core::panicking::panic_fmt
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/panicking.rs:80:14
   2: vtable_allocation_provider
             at /Users/timch/rust/compiler/rustc_middle/src/ty/vtable.rs:105:5
   3: {closure#0}
             at /Users/timch/rust/compiler/rustc_query_impl/src/plumbing.rs:294:9
      [... omitted 36 frames ...]
   4: query_get_at<rustc_query_system::query::caches::DefaultCache<(rustc_middle::ty::Ty, core::option::Option<rustc_type_ir::predicate::ExistentialTraitRef<rustc_middle::ty::context::TyCtxt>>), rustc_middle::query::erase::ErasedData<[u8; 8]>>>
             at /Users/timch/rust/compiler/rustc_middle/src/query/inner.rs:31:17
   5: vtable_allocation
             at /Users/timch/rust/compiler/rustc_middle/src/query/plumbing.rs:426:42
   6: vtable_allocation
             at /Users/timch/rust/compiler/rustc_middle/src/query/plumbing.rs:415:35
   7: collect_alloc
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:1291:32
   8: collect_const_value
   9: collect_items_of_instance
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:1356:13
  10: items_of_instance
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:1379:41
  11: {closure#0}
             at /Users/timch/rust/compiler/rustc_query_impl/src/plumbing.rs:294:9
      [... omitted 36 frames ...]
  12: query_get_at<rustc_query_system::query::caches::DefaultCache<(rustc_middle::ty::instance::Instance, rustc_middle::mir::mono::CollectionMode), rustc_middle::query::erase::ErasedData<[u8; 32]>>>
             at /Users/timch/rust/compiler/rustc_middle/src/query/inner.rs:31:17
  13: items_of_instance
             at /Users/timch/rust/compiler/rustc_middle/src/query/plumbing.rs:426:42
  14: items_of_instance
             at /Users/timch/rust/compiler/rustc_middle/src/query/plumbing.rs:415:35
  15: {closure#0}
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:481:49
  16: maybe_grow<(), rustc_monomorphize::collector::collect_items_rec::{closure_env#0}>
             at /Users/timch/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/stacker-0.1.21/src/lib.rs:57:9
  17: ensure_sufficient_stack<(), rustc_monomorphize::collector::collect_items_rec::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/stack.rs:21:5
  18: collect_items_rec
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:480:13
  19: collect_items_root
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:371:5
  20: {closure#0}
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:1824:13
  21: {closure#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/sync/parallel.rs:181:30
  22: call_once<(), rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure#1}::{closure_env#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/panic/unwind_safe.rs:274:9
  23: do_call<core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure#1}::{closure_env#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>, ()>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:581:40
  24: catch_unwind<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure#1}::{closure_env#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:544:19
  25: catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure#1}::{closure_env#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>, ()>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panic.rs:359:14
  26: run<(), rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure#1}::{closure_env#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>
             at /Users/timch/rust/compiler/rustc_data_structures/src/sync/parallel.rs:23:9
  27: {closure#1}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/sync/parallel.rs:181:23
  28: {closure#0}<rustc_middle::mir::mono::MonoItem, rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure_env#1}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/iter/traits/iterator.rs:829:29
  29: fold<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global, (), core::iter::traits::iterator::Iterator::for_each::call::{closure_env#0}<rustc_middle::mir::mono::MonoItem, rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure_env#1}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/alloc/src/vec/into_iter.rs:329:25
  30: for_each<alloc::vec::into_iter::IntoIter<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure_env#1}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/iter/traits/iterator.rs:832:14
  31: {closure#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/sync/parallel.rs:180:27
  32: parallel_guard<(), rustc_data_structures::sync::parallel::par_for_each_in::{closure_env#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>
             at /Users/timch/rust/compiler/rustc_data_structures/src/sync/parallel.rs:39:15
  33: par_for_each_in<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/sync/parallel.rs:175:5
  34: {closure#1}
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:1823:9
  35: run<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure_env#1}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/profiling.rs:844:9
  36: time<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure_env#1}>
             at /Users/timch/rust/compiler/rustc_session/src/utils.rs:17:50
  37: collect_crate_mono_items
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:1822:14
  38: collect_and_partition_mono_items
             at /Users/timch/rust/compiler/rustc_monomorphize/src/partitioning.rs:1138:30
  39: {closure#0}
             at /Users/timch/rust/compiler/rustc_query_impl/src/plumbing.rs:294:9
      [... omitted 33 frames ...]
  40: query_get_at<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 24]>>>
             at /Users/timch/rust/compiler/rustc_middle/src/query/inner.rs:31:17
  41: collect_and_partition_mono_items
             at /Users/timch/rust/compiler/rustc_middle/src/query/plumbing.rs:426:42
  42: collect_and_partition_mono_items
             at /Users/timch/rust/compiler/rustc_middle/src/query/plumbing.rs:415:35
  43: codegen_crate<rustc_codegen_llvm::LlvmCodegenBackend>
             at /Users/timch/rust/compiler/rustc_codegen_ssa/src/base.rs:695:56
  44: codegen_crate
             at /Users/timch/rust/compiler/rustc_codegen_llvm/src/lib.rs:354:18
  45: {closure#0}
             at /Users/timch/rust/compiler/rustc_interface/src/passes.rs:1264:29
  46: run<alloc::boxed::Box<dyn core::any::Any, alloc::alloc::Global>, rustc_interface::passes::start_codegen::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/profiling.rs:844:9
  47: time<alloc::boxed::Box<dyn core::any::Any, alloc::alloc::Global>, rustc_interface::passes::start_codegen::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_session/src/utils.rs:17:50
  48: start_codegen
             at /Users/timch/rust/compiler/rustc_interface/src/passes.rs:1252:28
  49: codegen_and_build_linker
             at /Users/timch/rust/compiler/rustc_interface/src/queries.rs:33:43
  50: {closure#2}
             at /Users/timch/rust/compiler/rustc_driver_impl/src/lib.rs:391:18
  51: {closure#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>
             at /Users/timch/rust/compiler/rustc_interface/src/passes.rs:1018:27
  52: {closure#1}<rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, core::option::Option<rustc_interface::queries::Linker>>
             at /Users/timch/rust/compiler/rustc_middle/src/ty/context.rs:1643:37
  53: {closure#0}<rustc_middle::ty::context::{impl#20}::enter::{closure_env#1}<rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, core::option::Option<rustc_interface::queries::Linker>>, core::option::Option<rustc_interface::queries::Linker>>
             at /Users/timch/rust/compiler/rustc_middle/src/ty/context/tls.rs:60:9
  54: try_with<core::cell::Cell<*const ()>, rustc_middle::ty::context::tls::enter_context::{closure_env#0}<rustc_middle::ty::context::{impl#20}::enter::{closure_env#1}<rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, core::option::Option<rustc_interface::queries::Linker>>, core::option::Option<rustc_interface::queries::Linker>>, core::option::Option<rustc_interface::queries::Linker>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/thread/local.rs:513:12
  55: with<core::cell::Cell<*const ()>, rustc_middle::ty::context::tls::enter_context::{closure_env#0}<rustc_middle::ty::context::{impl#20}::enter::{closure_env#1}<rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, core::option::Option<rustc_interface::queries::Linker>>, core::option::Option<rustc_interface::queries::Linker>>, core::option::Option<rustc_interface::queries::Linker>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/thread/local.rs:477:20
  56: enter_context<rustc_middle::ty::context::{impl#20}::enter::{closure_env#1}<rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, core::option::Option<rustc_interface::queries::Linker>>, core::option::Option<rustc_interface::queries::Linker>>
             at /Users/timch/rust/compiler/rustc_middle/src/ty/context/tls.rs:57:9
  57: enter<rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, core::option::Option<rustc_interface::queries::Linker>>
             at /Users/timch/rust/compiler/rustc_middle/src/ty/context.rs:1643:9
  58: create_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>>
             at /Users/timch/rust/compiler/rustc_middle/src/ty/context.rs:1850:13
  59: {closure#2}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>
             at /Users/timch/rust/compiler/rustc_interface/src/passes.rs:985:9
  60: call_once<rustc_interface::passes::create_and_enter_global_ctxt::{closure_env#2}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, (&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy, alloc::alloc::Global>, &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_env#2})>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/ops/function.rs:250:5
  61: call_once<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy, alloc::alloc::Global>, &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_env#2}), dyn core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy, alloc::alloc::Global>, &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_env#2}), Output=core::option::Option<rustc_interface::queries::Linker>>, alloc::alloc::Global>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/alloc/src/boxed.rs:2206:9
  62: create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>
             at /Users/timch/rust/compiler/rustc_interface/src/passes.rs:1026:5
  63: {closure#0}
             at /Users/timch/rust/compiler/rustc_driver_impl/src/lib.rs:348:22
  64: {closure#0}<(), rustc_driver_impl::run_compiler::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_interface/src/interface.rs:532:80
  65: call_once<(), rustc_interface::interface::run_compiler::{closure#1}::{closure_env#0}<(), rustc_driver_impl::run_compiler::{closure_env#0}>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/panic/unwind_safe.rs:274:9
  66: do_call<core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler::{closure#1}::{closure_env#0}<(), rustc_driver_impl::run_compiler::{closure_env#0}>>, ()>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:581:40
  67: catch_unwind<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler::{closure#1}::{closure_env#0}<(), rustc_driver_impl::run_compiler::{closure_env#0}>>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:544:19
  68: catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler::{closure#1}::{closure_env#0}<(), rustc_driver_impl::run_compiler::{closure_env#0}>>, ()>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panic.rs:359:14
  69: {closure#1}<(), rustc_driver_impl::run_compiler::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_interface/src/interface.rs:532:23
  70: {closure#0}<rustc_interface::interface::run_compiler::{closure_env#1}<(), rustc_driver_impl::run_compiler::{closure_env#0}>, ()>
             at /Users/timch/rust/compiler/rustc_interface/src/util.rs:204:17
  71: {closure#0}<rustc_interface::util::run_in_thread_pool_with_globals::{closure_env#0}<rustc_interface::interface::run_compiler::{closure_env#1}<(), rustc_driver_impl::run_compiler::{closure_env#0}>, ()>, ()>
             at /Users/timch/rust/compiler/rustc_interface/src/util.rs:158:24
  72: set<rustc_span::SessionGlobals, rustc_interface::util::run_in_thread_with_globals::{closure#0}::{closure#0}::{closure_env#0}<rustc_interface::util::run_in_thread_pool_with_globals::{closure_env#0}<rustc_interface::interface::run_compiler::{closure_env#1}<(), rustc_driver_impl::run_compiler::{closure_env#0}>, ()>, ()>, ()>
             at /Users/timch/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/scoped-tls-1.0.1/src/lib.rs:137:9
  73: create_session_globals_then<(), rustc_interface::util::run_in_thread_with_globals::{closure#0}::{closure#0}::{closure_env#0}<rustc_interface::util::run_in_thread_pool_with_globals::{closure_env#0}<rustc_interface::interface::run_compiler::{closure_env#1}<(), rustc_driver_impl::run_compiler::{closure_env#0}>, ()>, ()>>
             at /Users/timch/rust/compiler/rustc_span/src/lib.rs:142:21
  74: {closure#0}<rustc_interface::util::run_in_thread_pool_with_globals::{closure_env#0}<rustc_interface::interface::run_compiler::{closure_env#1}<(), rustc_driver_impl::run_compiler::{closure_env#0}>, ()>, ()>
             at /Users/timch/rust/compiler/rustc_interface/src/util.rs:154:17
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 `/Users/timch/foo/rustc-ice-2026-02-03T03_23_29-9322.txt` to your bug report

note: rustc 1.95.0-dev running on aarch64-apple-darwin

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED]

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

query stack during panic:
#0 [vtable_allocation] vtable const allocation for <[i32] as Trait>
#1 [items_of_instance] collecting items used by `main`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `foo` (bin "foo")

@theemathas
Copy link
Contributor

Failure to compute the layout of the type also results in an ICE with this PR.

#![feature(type_info)]

use std::any::TypeId;

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

pub fn main() {
    const { TypeId::of::<[u8; 1 << 63]>().trait_info_of_trait_type_id(TypeId::of::<dyn Trait>()) };
}
Error output
thread 'rustc' (91122) panicked at compiler/rustc_middle/src/ty/vtable.rs:104:10:
failed to build vtable representation: SizeOverflow([u8; 9223372036854775808_usize])
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:689:5
   1: core::panicking::panic_fmt
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/panicking.rs:80:14
   2: core::result::unwrap_failed
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/result.rs:1867:5
   3: expect<rustc_abi::layout::ty::TyAndLayout<rustc_middle::ty::Ty>, &rustc_middle::ty::layout::LayoutError>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/result.rs:1185:23
   4: vtable_allocation_provider
             at /Users/timch/rust/compiler/rustc_middle/src/ty/vtable.rs:104:10
   5: {closure#0}
             at /Users/timch/rust/compiler/rustc_query_impl/src/plumbing.rs:294:9
      [... omitted 36 frames ...]
   6: query_get_at<rustc_query_system::query::caches::DefaultCache<(rustc_middle::ty::Ty, core::option::Option<rustc_type_ir::predicate::ExistentialTraitRef<rustc_middle::ty::context::TyCtxt>>), rustc_middle::query::erase::ErasedData<[u8; 8]>>>
             at /Users/timch/rust/compiler/rustc_middle/src/query/inner.rs:31:17
   7: vtable_allocation
             at /Users/timch/rust/compiler/rustc_middle/src/query/plumbing.rs:426:42
   8: vtable_allocation
             at /Users/timch/rust/compiler/rustc_middle/src/query/plumbing.rs:415:35
   9: collect_alloc
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:1291:32
  10: collect_const_value
  11: collect_items_of_instance
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:1356:13
  12: items_of_instance
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:1379:41
  13: {closure#0}
             at /Users/timch/rust/compiler/rustc_query_impl/src/plumbing.rs:294:9
      [... omitted 36 frames ...]
  14: query_get_at<rustc_query_system::query::caches::DefaultCache<(rustc_middle::ty::instance::Instance, rustc_middle::mir::mono::CollectionMode), rustc_middle::query::erase::ErasedData<[u8; 32]>>>
             at /Users/timch/rust/compiler/rustc_middle/src/query/inner.rs:31:17
  15: items_of_instance
             at /Users/timch/rust/compiler/rustc_middle/src/query/plumbing.rs:426:42
  16: items_of_instance
             at /Users/timch/rust/compiler/rustc_middle/src/query/plumbing.rs:415:35
  17: {closure#0}
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:481:49
  18: maybe_grow<(), rustc_monomorphize::collector::collect_items_rec::{closure_env#0}>
             at /Users/timch/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/stacker-0.1.21/src/lib.rs:57:9
  19: ensure_sufficient_stack<(), rustc_monomorphize::collector::collect_items_rec::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/stack.rs:21:5
  20: collect_items_rec
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:480:13
  21: collect_items_root
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:371:5
  22: {closure#0}
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:1824:13
  23: {closure#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/sync/parallel.rs:181:30
  24: call_once<(), rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure#1}::{closure_env#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/panic/unwind_safe.rs:274:9
  25: do_call<core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure#1}::{closure_env#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>, ()>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:581:40
  26: catch_unwind<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure#1}::{closure_env#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:544:19
  27: catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure#1}::{closure_env#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>, ()>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panic.rs:359:14
  28: run<(), rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure#1}::{closure_env#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>
             at /Users/timch/rust/compiler/rustc_data_structures/src/sync/parallel.rs:23:9
  29: {closure#1}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/sync/parallel.rs:181:23
  30: {closure#0}<rustc_middle::mir::mono::MonoItem, rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure_env#1}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/iter/traits/iterator.rs:829:29
  31: fold<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global, (), core::iter::traits::iterator::Iterator::for_each::call::{closure_env#0}<rustc_middle::mir::mono::MonoItem, rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure_env#1}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/alloc/src/vec/into_iter.rs:329:25
  32: for_each<alloc::vec::into_iter::IntoIter<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_data_structures::sync::parallel::par_for_each_in::{closure#0}::{closure_env#1}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/iter/traits/iterator.rs:832:14
  33: {closure#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/sync/parallel.rs:180:27
  34: parallel_guard<(), rustc_data_structures::sync::parallel::par_for_each_in::{closure_env#0}<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>>
             at /Users/timch/rust/compiler/rustc_data_structures/src/sync/parallel.rs:39:15
  35: par_for_each_in<rustc_middle::mir::mono::MonoItem, alloc::vec::Vec<rustc_middle::mir::mono::MonoItem, alloc::alloc::Global>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/sync/parallel.rs:175:5
  36: {closure#1}
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:1823:9
  37: run<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure_env#1}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/profiling.rs:844:9
  38: time<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure_env#1}>
             at /Users/timch/rust/compiler/rustc_session/src/utils.rs:17:50
  39: collect_crate_mono_items
             at /Users/timch/rust/compiler/rustc_monomorphize/src/collector.rs:1822:14
  40: collect_and_partition_mono_items
             at /Users/timch/rust/compiler/rustc_monomorphize/src/partitioning.rs:1138:30
  41: {closure#0}
             at /Users/timch/rust/compiler/rustc_query_impl/src/plumbing.rs:294:9
      [... omitted 33 frames ...]
  42: query_get_at<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 24]>>>
             at /Users/timch/rust/compiler/rustc_middle/src/query/inner.rs:31:17
  43: collect_and_partition_mono_items
             at /Users/timch/rust/compiler/rustc_middle/src/query/plumbing.rs:426:42
  44: collect_and_partition_mono_items
             at /Users/timch/rust/compiler/rustc_middle/src/query/plumbing.rs:415:35
  45: codegen_crate<rustc_codegen_llvm::LlvmCodegenBackend>
             at /Users/timch/rust/compiler/rustc_codegen_ssa/src/base.rs:695:56
  46: codegen_crate
             at /Users/timch/rust/compiler/rustc_codegen_llvm/src/lib.rs:354:18
  47: {closure#0}
             at /Users/timch/rust/compiler/rustc_interface/src/passes.rs:1264:29
  48: run<alloc::boxed::Box<dyn core::any::Any, alloc::alloc::Global>, rustc_interface::passes::start_codegen::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_data_structures/src/profiling.rs:844:9
  49: time<alloc::boxed::Box<dyn core::any::Any, alloc::alloc::Global>, rustc_interface::passes::start_codegen::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_session/src/utils.rs:17:50
  50: start_codegen
             at /Users/timch/rust/compiler/rustc_interface/src/passes.rs:1252:28
  51: codegen_and_build_linker
             at /Users/timch/rust/compiler/rustc_interface/src/queries.rs:33:43
  52: {closure#2}
             at /Users/timch/rust/compiler/rustc_driver_impl/src/lib.rs:391:18
  53: {closure#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>
             at /Users/timch/rust/compiler/rustc_interface/src/passes.rs:1018:27
  54: {closure#1}<rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, core::option::Option<rustc_interface::queries::Linker>>
             at /Users/timch/rust/compiler/rustc_middle/src/ty/context.rs:1643:37
  55: {closure#0}<rustc_middle::ty::context::{impl#20}::enter::{closure_env#1}<rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, core::option::Option<rustc_interface::queries::Linker>>, core::option::Option<rustc_interface::queries::Linker>>
             at /Users/timch/rust/compiler/rustc_middle/src/ty/context/tls.rs:60:9
  56: try_with<core::cell::Cell<*const ()>, rustc_middle::ty::context::tls::enter_context::{closure_env#0}<rustc_middle::ty::context::{impl#20}::enter::{closure_env#1}<rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, core::option::Option<rustc_interface::queries::Linker>>, core::option::Option<rustc_interface::queries::Linker>>, core::option::Option<rustc_interface::queries::Linker>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/thread/local.rs:513:12
  57: with<core::cell::Cell<*const ()>, rustc_middle::ty::context::tls::enter_context::{closure_env#0}<rustc_middle::ty::context::{impl#20}::enter::{closure_env#1}<rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, core::option::Option<rustc_interface::queries::Linker>>, core::option::Option<rustc_interface::queries::Linker>>, core::option::Option<rustc_interface::queries::Linker>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/thread/local.rs:477:20
  58: enter_context<rustc_middle::ty::context::{impl#20}::enter::{closure_env#1}<rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, core::option::Option<rustc_interface::queries::Linker>>, core::option::Option<rustc_interface::queries::Linker>>
             at /Users/timch/rust/compiler/rustc_middle/src/ty/context/tls.rs:57:9
  59: enter<rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, core::option::Option<rustc_interface::queries::Linker>>
             at /Users/timch/rust/compiler/rustc_middle/src/ty/context.rs:1643:9
  60: create_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}::{closure_env#0}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>>
             at /Users/timch/rust/compiler/rustc_middle/src/ty/context.rs:1850:13
  61: {closure#2}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>
             at /Users/timch/rust/compiler/rustc_interface/src/passes.rs:985:9
  62: call_once<rustc_interface::passes::create_and_enter_global_ctxt::{closure_env#2}<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>, (&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy, alloc::alloc::Global>, &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_env#2})>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/ops/function.rs:250:5
  63: call_once<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy, alloc::alloc::Global>, &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_env#2}), dyn core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy, alloc::alloc::Global>, &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_env#2}), Output=core::option::Option<rustc_interface::queries::Linker>>, alloc::alloc::Global>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/alloc/src/boxed.rs:2206:9
  64: create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure_env#2}>
             at /Users/timch/rust/compiler/rustc_interface/src/passes.rs:1026:5
  65: {closure#0}
             at /Users/timch/rust/compiler/rustc_driver_impl/src/lib.rs:348:22
  66: {closure#0}<(), rustc_driver_impl::run_compiler::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_interface/src/interface.rs:532:80
  67: call_once<(), rustc_interface::interface::run_compiler::{closure#1}::{closure_env#0}<(), rustc_driver_impl::run_compiler::{closure_env#0}>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/panic/unwind_safe.rs:274:9
  68: do_call<core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler::{closure#1}::{closure_env#0}<(), rustc_driver_impl::run_compiler::{closure_env#0}>>, ()>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:581:40
  69: catch_unwind<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler::{closure#1}::{closure_env#0}<(), rustc_driver_impl::run_compiler::{closure_env#0}>>>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:544:19
  70: catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler::{closure#1}::{closure_env#0}<(), rustc_driver_impl::run_compiler::{closure_env#0}>>, ()>
             at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panic.rs:359:14
  71: {closure#1}<(), rustc_driver_impl::run_compiler::{closure_env#0}>
             at /Users/timch/rust/compiler/rustc_interface/src/interface.rs:532:23
  72: {closure#0}<rustc_interface::interface::run_compiler::{closure_env#1}<(), rustc_driver_impl::run_compiler::{closure_env#0}>, ()>
             at /Users/timch/rust/compiler/rustc_interface/src/util.rs:204:17
  73: {closure#0}<rustc_interface::util::run_in_thread_pool_with_globals::{closure_env#0}<rustc_interface::interface::run_compiler::{closure_env#1}<(), rustc_driver_impl::run_compiler::{closure_env#0}>, ()>, ()>
             at /Users/timch/rust/compiler/rustc_interface/src/util.rs:158:24
  74: set<rustc_span::SessionGlobals, rustc_interface::util::run_in_thread_with_globals::{closure#0}::{closure#0}::{closure_env#0}<rustc_interface::util::run_in_thread_pool_with_globals::{closure_env#0}<rustc_interface::interface::run_compiler::{closure_env#1}<(), rustc_driver_impl::run_compiler::{closure_env#0}>, ()>, ()>, ()>
             at /Users/timch/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/scoped-tls-1.0.1/src/lib.rs:137:9
  75: create_session_globals_then<(), rustc_interface::util::run_in_thread_with_globals::{closure#0}::{closure#0}::{closure_env#0}<rustc_interface::util::run_in_thread_pool_with_globals::{closure_env#0}<rustc_interface::interface::run_compiler::{closure_env#1}<(), rustc_driver_impl::run_compiler::{closure_env#0}>, ()>, ()>>
             at /Users/timch/rust/compiler/rustc_span/src/lib.rs:142:21
  76: {closure#0}<rustc_interface::util::run_in_thread_pool_with_globals::{closure_env#0}<rustc_interface::interface::run_compiler::{closure_env#1}<(), rustc_driver_impl::run_compiler::{closure_env#0}>, ()>, ()>
             at /Users/timch/rust/compiler/rustc_interface/src/util.rs:154:17
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 `/Users/timch/foo/rustc-ice-2026-02-03T03_37_20-10469.txt` to your bug report

note: rustc 1.95.0-dev running on aarch64-apple-darwin

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED]

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 `main`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `foo` (bin "foo")

@oli-obk
Copy link
Contributor

oli-obk commented Feb 3, 2026

Do any of the issues mentioned so far apply to the existing functions on nightly, too? If so, we should address them there first and add tests for them

@theemathas
Copy link
Contributor

theemathas commented Feb 3, 2026

@oli-obk

type_info gives a reasonable error when faced with layout computation errors

Code & Error 1
#![feature(type_info)]

fn main() {
    dbg!(const {
        std::any::TypeId::of::<[u8; 1<<63]>().info()
    });
}
error[E0080]: values of the type `[u8; 9223372036854775808]` are too big for the target architecture
  --> src/main.rs:5:9
   |
 5 |         std::any::TypeId::of::<[u8; 1<<63]>().info()
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::{constant#0}` failed inside this call
   |
note: inside `type_info::<impl TypeId>::info`
  --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/type_info.rs:25:9
   |
25 |         type_of(self)
   |         ^^^^^^^^^^^^^ the failure occurred here

For more information about this error, try `rustc --explain E0080`.
Code & Error 2
#![feature(type_info)]

trait Apply {
    type Output<T>;
}
struct Identity;
impl Apply for Identity {
    type Output<T> = T;
}

struct Thing<A: Apply>(<A as Apply>::Output<Self>);

/*
Effectively:
struct Thing_Identity(Thing_Identity);
*/

fn main() {
    dbg!(const {
        std::any::TypeId::of::<Thing<Identity>>().info()
    });
}
error[E0391]: cycle detected when computing layout of `Thing<Identity>`
   |
   = note: ...which requires computing layout of `<Identity as Apply>::Output<Thing<Identity>>`...
   = note: ...which again requires computing layout of `Thing<Identity>`, completing the cycle
note: cycle used when const-evaluating + checking `main::{constant#0}`
  --> src/main.rs:19:16
   |
19 |       dbg!(const {
   |  ________________^
20 | |         std::any::TypeId::of::<Thing<Identity>>().info()
21 | |     });
   | |_____^
   = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

error[E0080]: a cycle occurred during layout computation
  --> src/main.rs:20:9
   |
20 |         std::any::TypeId::of::<Thing<Identity>>().info()
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::{constant#0}` failed inside this call
   |
note: inside `type_info::<impl TypeId>::info`
  --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/type_info.rs:25:9
   |
25 |         type_of(self)
   |         ^^^^^^^^^^^^^ the failure occurred here

Some errors have detailed explanations: E0080, E0391.
For more information about an error, try `rustc --explain E0080`.

try_as_dyn has a similar issue with this PR with regards to layout computation errors. I've filed this as #152030.

I think neither type_info nor try_as_dyn will attempt to create a vtable for a DST.

@9SonSteroids
Copy link
Author

Trying to create a vtable for a DST results in an ICE with this PR.

#![feature(type_info)]

use std::any::TypeId;

trait Trait {}
impl Trait for [i32] {}

fn main() {
    const { TypeId::of::<[i32]>().trait_info_of_trait_type_id(TypeId::of::<dyn Trait>()) };
}

Error output

According to my understanding DST's cannot be converted to dyn, right? So returning None would be correct?

@9SonSteroids
Copy link
Author

Failure to compute the layout of the type also results in an ICE with this PR.

#![feature(type_info)]

use std::any::TypeId;

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

pub fn main() {
    const { TypeId::of::<[u8; 1 << 63]>().trait_info_of_trait_type_id(TypeId::of::<dyn Trait>()) };
}

Error output

I don't get this ICE on arch linux, x86_64 cpu. I added a ui test for this.

@9SonSteroids
Copy link
Author

violating this documentation. Is this a p

This is not a problem because both functions return None when attempting to get the vtable of a non dyn Type.

@9SonSteroids
Copy link
Author

bors r+

@theemathas
Copy link
Contributor

According to my understanding DST's cannot be converted to dyn, right? So returning None would be correct?

Yes

I don't get this ICE on arch linux, x86_64 cpu. I added a ui test for this.

Your latest commit calls .info() in trait_info_of_trait_type_id. It seems that the .info() call failed before getting to call the intrinsic, which avoids the ICE.

This is not a problem because both functions return None when attempting to get the vtable of a non dyn Type.

That's not how it works. Here's code that produces a DynMetadata<*const ()> at run time.

#![feature(type_info, ptr_metadata)]

use std::{any::TypeId, ptr::DynMetadata};

struct Thing;
trait Trait {}
impl Trait for Thing {}

pub fn main() {
    let metadata: DynMetadata<*const ()> =
        const { TypeId::of::<Thing>().trait_info_of_trait_type_id(TypeId::of::<dyn Trait>()) }
            .unwrap()
            .get_vtable();
    println!("{metadata:?}");
}

@rust-log-analyzer

This comment has been minimized.

@9SonSteroids
Copy link
Author

According to my understanding DST's cannot be converted to dyn, right? So returning None would be correct?

Yes

I don't get this ICE on arch linux, x86_64 cpu. I added a ui test for this.

Your latest commit calls .info() in trait_info_of_trait_type_id. It seems that the .info() call failed before getting to call the intrinsic, which avoids the ICE.

This is not a problem because both functions return None when attempting to get the vtable of a non dyn Type.

That's not how it works. Here's code that produces a DynMetadata<*const ()> at run time.

#![feature(type_info, ptr_metadata)]

use std::{any::TypeId, ptr::DynMetadata};

struct Thing;
trait Trait {}
impl Trait for Thing {}

pub fn main() {
    let metadata: DynMetadata<*const ()> =
        const { TypeId::of::<Thing>().trait_info_of_trait_type_id(TypeId::of::<dyn Trait>()) }
            .unwrap()
            .get_vtable();
    println!("{metadata:?}");
}

So what should we do? The trait_info_of_trait_type_id vtable is for unknown dyn type. We could make this function just return a bool.

@9SonSteroids
Copy link
Author

The job x86_64-gnu-llvm-20 failed! Check out the build log: (web) (plain enhanced) (plain)
Click to see the possible cause of the failure (guessed by this bot)

REPOSITORY                                   TAG       IMAGE ID       CREATED      SIZE
ghcr.io/dependabot/dependabot-updater-core   latest    bcec0b4e062b   7 days ago   783MB
=> Removing docker images...
Deleted Images:
untagged: ghcr.io/dependabot/dependabot-updater-core:latest
untagged: ghcr.io/dependabot/dependabot-updater-core@sha256:b662be51f7b8ef7e2c8464428f14e49cb79c36aa9afb7ecb9221dfe0f507050c
deleted: sha256:bcec0b4e062b5ffe11cc1c2729558c0cd96621c0271ab5e97ff3a56e0c25045a
deleted: sha256:64e147d5e54d9be8b8aa322e511cda02296eda4b8b8d063c6a314833aca50e29
deleted: sha256:5cba409bb463f4e7fa1a19f695450170422582c1bc7c0e934d893b4e5f558bc6
deleted: sha256:cddc6ebd344b0111eaab170ead1dfda24acdfe865ed8a12599a34d338fa8e28b
deleted: sha256:2412c3f334d79134573cd45e657fb6cc0abd75bef3881458b0d498d936545c8d
---
test [ui] tests/ui/asm/aarch64/type-f16.rs ... ignored, only executed when the architecture is aarch64
test [ui] tests/ui/array-slice-vec/vector-no-ann.rs ... ok
test [ui] tests/ui/array-slice-vec/vector-slice-matching-8498.rs ... ok
test [ui] tests/ui/asm/aarch64/arm64ec-sve.rs ... ok
test [ui] tests/ui/asm/aarch64v8r.rs#hf ... ok
test [ui] tests/ui/asm/aarch64v8r.rs#sf ... ok
test [ui] tests/ui/asm/aarch64v8r.rs#r82 ... ok
test [ui] tests/ui/asm/asm-with-nested-closure.rs ... ok
test [ui] tests/ui/asm/binary_asm_labels.rs ... ignored, only executed when the architecture is x86_64
test [ui] tests/ui/asm/binary_asm_labels_allowed.rs ... ignored, only executed when the architecture is aarch64
test [ui] tests/ui/asm/arm-low-dreg.rs ... ok
test [ui] tests/ui/asm/cfg.rs#reva ... ignored, only executed when the architecture is x86_64
---
test [ui] tests/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs#thin2 ... ok
test [ui] tests/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs#thin0 ... ok
test [ui] tests/ui/extern/issue-95829.rs ... ok
test [ui] tests/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs#thin3 ... ok
test [ui] tests/ui/extern/lgamma-linkage.rs ... ok
test [ui] tests/ui/extern/not-in-block.rs ... ok
test [ui] tests/ui/extern/unsized-extern-derefmove.rs ... ok
test [ui] tests/ui/extern/windows-tcb-trash-13259.rs ... ok
test [ui] tests/ui/feature-gates/allow-features-empty.rs ... ok
test [ui] tests/ui/feature-gates/allow-features.rs ... ok
---
test [ui] tests/ui/imports/ambiguous-9.rs ... ok
test [ui] tests/ui/imports/ambiguous-import-visibility-module.rs ... ok
test [ui] tests/ui/imports/ambiguous-8.rs ... ok
test [ui] tests/ui/imports/ambiguous-glob-vs-expanded-extern.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-glob-vs-multiouter.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-globvsglob.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-no-implicit-prelude.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-non-prelude-core-glob.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-non-prelude-std-glob.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-pick-core.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-pick-std.rs ... ok
---
test [ui] tests/ui/zero-sized/zero-sized-btreemap-insert.rs ... ok

failures:

---- [ui] tests/ui/reflection/trait_info_of_too_big.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/reflection/trait_info_of_too_big/trait_info_of_too_big.stderr`
diff of stderr:

- error[E0080]: values of the type `[u8; 9223372036854775808]` are too big for the target architecture
-   --> $DIR/trait_info_of_too_big.rs:13:5
+ error[E0080]: attempt to shift left by `63_i32`, which would overflow
+   --> $DIR/trait_info_of_too_big.rs:8:21
3    |
- LL |     TypeId::of::<[u8; 1 << 63]>().trait_info_of_trait_type_id(TypeId::of::<dyn Trait>());
-    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_::{constant#0}` failed inside this call
+ LL | impl Trait for [u8; 1 << 63] {}
+    |                     ^^^^^^^ evaluation of `<[u8; 1 << 63] as Trait>::{constant#0}` failed here
+ 
+ error[E0080]: attempt to shift left by `63_i32`, which would overflow
+   --> $DIR/trait_info_of_too_big.rs:13:23
6    |
- note: inside `TypeId::trait_info_of_trait_type_id`
-   --> $SRC_DIR/core/src/any.rs:LL:COL
- note: inside `type_info::<impl TypeId>::info`
-   --> $SRC_DIR/core/src/mem/type_info.rs:LL:COL
+ LL |     TypeId::of::<[u8; 1 << 63]>().trait_info_of_trait_type_id(TypeId::of::<dyn Trait>());
+    |                       ^^^^^^^ evaluation of `_::{constant#0}::{constant#0}` failed here
11 
- error[E0080]: values of the type `[u8; 9223372036854775808]` are too big for the target architecture
-   --> $DIR/trait_info_of_too_big.rs:17:5
+ error[E0080]: attempt to shift left by `63_i32`, which would overflow
+   --> $DIR/trait_info_of_too_big.rs:17:23
14    |
15 LL |     TypeId::of::<[u8; 1 << 63]>().trait_info_of::<dyn Trait>();
-    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_::{constant#0}` failed inside this call
-    |
- note: inside `TypeId::trait_info_of::<dyn Trait>`
-   --> $SRC_DIR/core/src/any.rs:LL:COL
- note: inside `TypeId::trait_info_of_trait_type_id`
-   --> $SRC_DIR/core/src/any.rs:LL:COL
- note: inside `type_info::<impl TypeId>::info`
-   --> $SRC_DIR/core/src/mem/type_info.rs:LL:COL
+    |                       ^^^^^^^ evaluation of `_::{constant#0}::{constant#0}` failed here
24 
- error: aborting due to 2 previous errors
+ error: aborting due to 3 previous errors
26 
27 For more information about this error, try `rustc --explain E0080`.
28 

Note: some mismatched output was normalized before being compared
-   --> /checkout/tests/ui/reflection/trait_info_of_too_big.rs:8:21
-   --> /checkout/tests/ui/reflection/trait_info_of_too_big.rs:13:23
-   --> /checkout/tests/ui/reflection/trait_info_of_too_big.rs:17:23
+ error[E0080]: attempt to shift left by `63_i32`, which would overflow
+   --> $DIR/trait_info_of_too_big.rs:8:21
+ LL | impl Trait for [u8; 1 << 63] {}
+    |                     ^^^^^^^ evaluation of `<[u8; 1 << 63] as Trait>::{constant#0}` failed here
+ 
+ error[E0080]: attempt to shift left by `63_i32`, which would overflow
+   --> $DIR/trait_info_of_too_big.rs:13:23
+    |
+    |                       ^^^^^^^ evaluation of `_::{constant#0}::{constant#0}` failed here
+ error[E0080]: attempt to shift left by `63_i32`, which would overflow
+   --> $DIR/trait_info_of_too_big.rs:17:23
+    |                       ^^^^^^^ evaluation of `_::{constant#0}::{constant#0}` failed here
+ error: aborting due to 3 previous errors


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args reflection/trait_info_of_too_big.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/reflection/trait_info_of_too_big.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=i686-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/reflection/trait_info_of_too_big" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/i686-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=x86_64-linux-gnu-gcc"
stdout: none
--- stderr -------------------------------
error[E0080]: attempt to shift left by `63_i32`, which would overflow
##[error]  --> /checkout/tests/ui/reflection/trait_info_of_too_big.rs:8:21
   |
LL | impl Trait for [u8; 1 << 63] {}
   |                     ^^^^^^^ evaluation of `<[u8; 1 << 63] as Trait>::{constant#0}` failed here

error[E0080]: attempt to shift left by `63_i32`, which would overflow
##[error]  --> /checkout/tests/ui/reflection/trait_info_of_too_big.rs:13:23
   |
LL |     TypeId::of::<[u8; 1 << 63]>().trait_info_of_trait_type_id(TypeId::of::<dyn Trait>());
   |                       ^^^^^^^ evaluation of `_::{constant#0}::{constant#0}` failed here

error[E0080]: attempt to shift left by `63_i32`, which would overflow
##[error]  --> /checkout/tests/ui/reflection/trait_info_of_too_big.rs:17:23
   |
LL |     TypeId::of::<[u8; 1 << 63]>().trait_info_of::<dyn Trait>();
   |                       ^^^^^^^ evaluation of `_::{constant#0}::{constant#0}` failed here

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0080`.
------------------------------------------

Guess I have to adapt it to from 1 << 63 to 1 << bitness-1

@programmerjake
Copy link
Member

Guess I have to adapt it to from 1 << 63 to 1 << bitness-1

you can use [u8; usize::MAX]

@rust-log-analyzer

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-type_info #![feature(type_info)] S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants