Skip to content

Commit

Permalink
Also fix first_method_vtable_slot
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Sep 30, 2024
1 parent d87e0ca commit 7c552d5
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions compiler/rustc_trait_selection/src/traits/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,10 @@ pub(crate) fn first_method_vtable_slot<'tcx>(tcx: TyCtxt<'tcx>, key: ty::TraitRe
let ty::Dynamic(source, _, _) = *key.self_ty().kind() else {
bug!();
};
let source_principal = tcx
.normalize_erasing_regions(ty::ParamEnv::reveal_all(), source.principal().unwrap())
.with_self_ty(tcx, tcx.types.trait_object_dummy_self);
let source_principal =
source.principal().unwrap().with_self_ty(tcx, tcx.types.trait_object_dummy_self);

let target_principal = tcx
.normalize_erasing_regions(ty::ParamEnv::reveal_all(), key)
// We don't care about the self type, since it will always be the same thing.
.with_self_ty(tcx, tcx.types.trait_object_dummy_self);
let target_principal = ty::Binder::dummy(ty::ExistentialTraitRef::erase_self_ty(tcx, key));

let vtable_segment_callback = {
let mut vptr_offset = 0;
Expand All @@ -348,15 +344,18 @@ pub(crate) fn first_method_vtable_slot<'tcx>(tcx: TyCtxt<'tcx>, key: ty::TraitRe
VtblSegment::MetadataDSA => {
vptr_offset += TyCtxt::COMMON_VTABLE_ENTRIES.len();
}
VtblSegment::TraitOwnEntries { trait_ref, emit_vptr } => {
if tcx
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), trait_ref)
== target_principal
{
VtblSegment::TraitOwnEntries { trait_ref: vtable_principal, emit_vptr } => {
if trait_refs_are_compatible(
tcx,
vtable_principal
.map_bound(|t| ty::ExistentialTraitRef::erase_self_ty(tcx, t)),
target_principal,
) {
return ControlFlow::Break(vptr_offset);
}

vptr_offset += tcx.own_existential_vtable_entries(trait_ref.def_id()).len();
vptr_offset +=
tcx.own_existential_vtable_entries(vtable_principal.def_id()).len();

if emit_vptr {
vptr_offset += 1;
Expand Down

0 comments on commit 7c552d5

Please sign in to comment.