Don't call own_existential_vtable_entries
on unresolved trait ref
This commit is contained in:
parent
a6b5f95fb0
commit
1e2eb97c6e
3 changed files with 8 additions and 19 deletions
|
@ -1207,9 +1207,9 @@ rustc_queries! {
|
||||||
}
|
}
|
||||||
|
|
||||||
query own_existential_vtable_entries(
|
query own_existential_vtable_entries(
|
||||||
key: ty::PolyExistentialTraitRef<'tcx>
|
key: DefId
|
||||||
) -> &'tcx [DefId] {
|
) -> &'tcx [DefId] {
|
||||||
desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key.def_id()) }
|
desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key) }
|
||||||
}
|
}
|
||||||
|
|
||||||
query vtable_entries(key: ty::PolyTraitRef<'tcx>)
|
query vtable_entries(key: ty::PolyTraitRef<'tcx>)
|
||||||
|
|
|
@ -764,12 +764,9 @@ fn dump_vtable_entries<'tcx>(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn own_existential_vtable_entries<'tcx>(
|
fn own_existential_vtable_entries<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId) -> &'tcx [DefId] {
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
trait_ref: ty::PolyExistentialTraitRef<'tcx>,
|
|
||||||
) -> &'tcx [DefId] {
|
|
||||||
let trait_methods = tcx
|
let trait_methods = tcx
|
||||||
.associated_items(trait_ref.def_id())
|
.associated_items(trait_def_id)
|
||||||
.in_definition_order()
|
.in_definition_order()
|
||||||
.filter(|item| item.kind == ty::AssocKind::Fn);
|
.filter(|item| item.kind == ty::AssocKind::Fn);
|
||||||
// Now list each method's DefId (for within its trait).
|
// Now list each method's DefId (for within its trait).
|
||||||
|
@ -778,7 +775,7 @@ fn own_existential_vtable_entries<'tcx>(
|
||||||
let def_id = trait_method.def_id;
|
let def_id = trait_method.def_id;
|
||||||
|
|
||||||
// Some methods cannot be called on an object; skip those.
|
// Some methods cannot be called on an object; skip those.
|
||||||
if !is_vtable_safe_method(tcx, trait_ref.def_id(), &trait_method) {
|
if !is_vtable_safe_method(tcx, trait_def_id, &trait_method) {
|
||||||
debug!("own_existential_vtable_entry: not vtable safe");
|
debug!("own_existential_vtable_entry: not vtable safe");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -810,7 +807,7 @@ fn vtable_entries<'tcx>(
|
||||||
|
|
||||||
// Lookup the shape of vtable for the trait.
|
// Lookup the shape of vtable for the trait.
|
||||||
let own_existential_entries =
|
let own_existential_entries =
|
||||||
tcx.own_existential_vtable_entries(existential_trait_ref);
|
tcx.own_existential_vtable_entries(existential_trait_ref.def_id());
|
||||||
|
|
||||||
let own_entries = own_existential_entries.iter().copied().map(|def_id| {
|
let own_entries = own_existential_entries.iter().copied().map(|def_id| {
|
||||||
debug!("vtable_entries: trait_method={:?}", def_id);
|
debug!("vtable_entries: trait_method={:?}", def_id);
|
||||||
|
|
|
@ -268,10 +268,7 @@ pub fn count_own_vtable_entries<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||||
) -> usize {
|
) -> usize {
|
||||||
let existential_trait_ref =
|
tcx.own_existential_vtable_entries(trait_ref.def_id()).len()
|
||||||
trait_ref.map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref));
|
|
||||||
let existential_trait_ref = tcx.erase_regions(existential_trait_ref);
|
|
||||||
tcx.own_existential_vtable_entries(existential_trait_ref).len()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given an upcast trait object described by `object`, returns the
|
/// Given an upcast trait object described by `object`, returns the
|
||||||
|
@ -282,15 +279,10 @@ pub fn get_vtable_index_of_object_method<'tcx, N>(
|
||||||
object: &super::ImplSourceObjectData<'tcx, N>,
|
object: &super::ImplSourceObjectData<'tcx, N>,
|
||||||
method_def_id: DefId,
|
method_def_id: DefId,
|
||||||
) -> Option<usize> {
|
) -> Option<usize> {
|
||||||
let existential_trait_ref = object
|
|
||||||
.upcast_trait_ref
|
|
||||||
.map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref));
|
|
||||||
let existential_trait_ref = tcx.erase_regions(existential_trait_ref);
|
|
||||||
|
|
||||||
// Count number of methods preceding the one we are selecting and
|
// Count number of methods preceding the one we are selecting and
|
||||||
// add them to the total offset.
|
// add them to the total offset.
|
||||||
if let Some(index) = tcx
|
if let Some(index) = tcx
|
||||||
.own_existential_vtable_entries(existential_trait_ref)
|
.own_existential_vtable_entries(object.upcast_trait_ref.def_id())
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.position(|def_id| def_id == method_def_id)
|
.position(|def_id| def_id == method_def_id)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue