Skip to content

Commit 7c552d5

Browse files
Also fix first_method_vtable_slot
1 parent d87e0ca commit 7c552d5

File tree

1 file changed

+12
-13
lines changed
  • compiler/rustc_trait_selection/src/traits

1 file changed

+12
-13
lines changed

compiler/rustc_trait_selection/src/traits/vtable.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,10 @@ pub(crate) fn first_method_vtable_slot<'tcx>(tcx: TyCtxt<'tcx>, key: ty::TraitRe
332332
let ty::Dynamic(source, _, _) = *key.self_ty().kind() else {
333333
bug!();
334334
};
335-
let source_principal = tcx
336-
.normalize_erasing_regions(ty::ParamEnv::reveal_all(), source.principal().unwrap())
337-
.with_self_ty(tcx, tcx.types.trait_object_dummy_self);
335+
let source_principal =
336+
source.principal().unwrap().with_self_ty(tcx, tcx.types.trait_object_dummy_self);
338337

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

344340
let vtable_segment_callback = {
345341
let mut vptr_offset = 0;
@@ -348,15 +344,18 @@ pub(crate) fn first_method_vtable_slot<'tcx>(tcx: TyCtxt<'tcx>, key: ty::TraitRe
348344
VtblSegment::MetadataDSA => {
349345
vptr_offset += TyCtxt::COMMON_VTABLE_ENTRIES.len();
350346
}
351-
VtblSegment::TraitOwnEntries { trait_ref, emit_vptr } => {
352-
if tcx
353-
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), trait_ref)
354-
== target_principal
355-
{
347+
VtblSegment::TraitOwnEntries { trait_ref: vtable_principal, emit_vptr } => {
348+
if trait_refs_are_compatible(
349+
tcx,
350+
vtable_principal
351+
.map_bound(|t| ty::ExistentialTraitRef::erase_self_ty(tcx, t)),
352+
target_principal,
353+
) {
356354
return ControlFlow::Break(vptr_offset);
357355
}
358356

359-
vptr_offset += tcx.own_existential_vtable_entries(trait_ref.def_id()).len();
357+
vptr_offset +=
358+
tcx.own_existential_vtable_entries(vtable_principal.def_id()).len();
360359

361360
if emit_vptr {
362361
vptr_offset += 1;

0 commit comments

Comments
 (0)