1
Fork 0

Do not treat vtable supertraits as distinct when bound with different bound vars

This commit is contained in:
Michael Goulet 2025-01-10 04:36:11 +00:00
parent 37a430e6ea
commit fdc4bd22b7
18 changed files with 146 additions and 115 deletions

View file

@ -1138,11 +1138,12 @@ fn create_mono_items_for_vtable_methods<'tcx>(
bug!("create_mono_items_for_vtable_methods: {trait_ty:?} not a trait type");
};
if let Some(principal) = trait_ty.principal() {
let poly_trait_ref = principal.with_self_ty(tcx, impl_ty);
assert!(!poly_trait_ref.has_escaping_bound_vars());
let trait_ref =
tcx.instantiate_bound_regions_with_erased(principal.with_self_ty(tcx, impl_ty));
assert!(!trait_ref.has_escaping_bound_vars());
// Walk all methods of the trait, including those of its supertraits
let entries = tcx.vtable_entries(poly_trait_ref);
let entries = tcx.vtable_entries(trait_ref);
debug!(?entries);
let methods = entries
.iter()
@ -1197,7 +1198,12 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
}
}
GlobalAlloc::VTable(ty, dyn_ty) => {
let alloc_id = tcx.vtable_allocation((ty, dyn_ty.principal()));
let alloc_id = tcx.vtable_allocation((
ty,
dyn_ty
.principal()
.map(|principal| tcx.instantiate_bound_regions_with_erased(principal)),
));
collect_alloc(tcx, alloc_id, output)
}
}