about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret/cast.rs
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-01-10 04:47:45 +0000
committerMichael Goulet <michael@errs.io>2025-01-30 15:34:00 +0000
commit739ef83f318defbb9692029fa98f56639896c6fd (patch)
treecfe995feb5405d026522872a8388e419ec2ea157 /compiler/rustc_const_eval/src/interpret/cast.rs
parentfdc4bd22b7b8117f4a3864c342773df600f5b956 (diff)
downloadrust-739ef83f318defbb9692029fa98f56639896c6fd.tar.gz
rust-739ef83f318defbb9692029fa98f56639896c6fd.zip
Normalize vtable entries before walking and deduplicating them
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/cast.rs')
-rw-r--r--compiler/rustc_const_eval/src/interpret/cast.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs
index b05efd10e66..52bc2af928d 100644
--- a/compiler/rustc_const_eval/src/interpret/cast.rs
+++ b/compiler/rustc_const_eval/src/interpret/cast.rs
@@ -419,7 +419,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
                         self.tcx.supertrait_vtable_slot((src_pointee_ty, dest_pointee_ty));
                     let vtable_entries = self.vtable_entries(data_a.principal(), ty);
                     if let Some(entry_idx) = vptr_entry_idx {
-                        let Some(&ty::VtblEntry::TraitVPtr(_)) = vtable_entries.get(entry_idx)
+                        let Some(&ty::VtblEntry::TraitVPtr(upcast_trait_ref)) =
+                            vtable_entries.get(entry_idx)
                         else {
                             span_bug!(
                                 self.cur_span(),
@@ -428,6 +429,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
                                 dest_pointee_ty
                             );
                         };
+                        let erased_trait_ref =
+                            ty::ExistentialTraitRef::erase_self_ty(*self.tcx, upcast_trait_ref);
+                        assert!(data_b.principal().is_some_and(|b| self.eq_in_param_env(
+                            erased_trait_ref,
+                            self.tcx.instantiate_bound_regions_with_erased(b)
+                        )));
                     } else {
                         // In this case codegen would keep using the old vtable. We don't want to do
                         // that as it has the wrong trait. The reason codegen can do this is that