@@ -332,14 +332,10 @@ pub(crate) fn first_method_vtable_slot<'tcx>(tcx: TyCtxt<'tcx>, key: ty::TraitRe
332
332
let ty:: Dynamic ( source, _, _) = * key. self_ty ( ) . kind ( ) else {
333
333
bug ! ( ) ;
334
334
} ;
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 ) ;
338
337
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) ) ;
343
339
344
340
let vtable_segment_callback = {
345
341
let mut vptr_offset = 0 ;
@@ -348,15 +344,18 @@ pub(crate) fn first_method_vtable_slot<'tcx>(tcx: TyCtxt<'tcx>, key: ty::TraitRe
348
344
VtblSegment :: MetadataDSA => {
349
345
vptr_offset += TyCtxt :: COMMON_VTABLE_ENTRIES . len ( ) ;
350
346
}
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
+ ) {
356
354
return ControlFlow :: Break ( vptr_offset) ;
357
355
}
358
356
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 ( ) ;
360
359
361
360
if emit_vptr {
362
361
vptr_offset += 1 ;
0 commit comments