Skip to content

Commit 1e2eb97

Browse files
Don't call own_existential_vtable_entries on unresolved trait ref
1 parent a6b5f95 commit 1e2eb97

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

compiler/rustc_middle/src/query/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1207,9 +1207,9 @@ rustc_queries! {
12071207
}
12081208

12091209
query own_existential_vtable_entries(
1210-
key: ty::PolyExistentialTraitRef<'tcx>
1210+
key: DefId
12111211
) -> &'tcx [DefId] {
1212-
desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key.def_id()) }
1212+
desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key) }
12131213
}
12141214

12151215
query vtable_entries(key: ty::PolyTraitRef<'tcx>)

compiler/rustc_trait_selection/src/traits/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,9 @@ fn dump_vtable_entries<'tcx>(
764764
});
765765
}
766766

767-
fn own_existential_vtable_entries<'tcx>(
768-
tcx: TyCtxt<'tcx>,
769-
trait_ref: ty::PolyExistentialTraitRef<'tcx>,
770-
) -> &'tcx [DefId] {
767+
fn own_existential_vtable_entries<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId) -> &'tcx [DefId] {
771768
let trait_methods = tcx
772-
.associated_items(trait_ref.def_id())
769+
.associated_items(trait_def_id)
773770
.in_definition_order()
774771
.filter(|item| item.kind == ty::AssocKind::Fn);
775772
// Now list each method's DefId (for within its trait).
@@ -778,7 +775,7 @@ fn own_existential_vtable_entries<'tcx>(
778775
let def_id = trait_method.def_id;
779776

780777
// Some methods cannot be called on an object; skip those.
781-
if !is_vtable_safe_method(tcx, trait_ref.def_id(), &trait_method) {
778+
if !is_vtable_safe_method(tcx, trait_def_id, &trait_method) {
782779
debug!("own_existential_vtable_entry: not vtable safe");
783780
return None;
784781
}
@@ -810,7 +807,7 @@ fn vtable_entries<'tcx>(
810807

811808
// Lookup the shape of vtable for the trait.
812809
let own_existential_entries =
813-
tcx.own_existential_vtable_entries(existential_trait_ref);
810+
tcx.own_existential_vtable_entries(existential_trait_ref.def_id());
814811

815812
let own_entries = own_existential_entries.iter().copied().map(|def_id| {
816813
debug!("vtable_entries: trait_method={:?}", def_id);

compiler/rustc_trait_selection/src/traits/util.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,7 @@ pub fn count_own_vtable_entries<'tcx>(
268268
tcx: TyCtxt<'tcx>,
269269
trait_ref: ty::PolyTraitRef<'tcx>,
270270
) -> usize {
271-
let existential_trait_ref =
272-
trait_ref.map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref));
273-
let existential_trait_ref = tcx.erase_regions(existential_trait_ref);
274-
tcx.own_existential_vtable_entries(existential_trait_ref).len()
271+
tcx.own_existential_vtable_entries(trait_ref.def_id()).len()
275272
}
276273

277274
/// Given an upcast trait object described by `object`, returns the
@@ -282,15 +279,10 @@ pub fn get_vtable_index_of_object_method<'tcx, N>(
282279
object: &super::ImplSourceObjectData<'tcx, N>,
283280
method_def_id: DefId,
284281
) -> Option<usize> {
285-
let existential_trait_ref = object
286-
.upcast_trait_ref
287-
.map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref));
288-
let existential_trait_ref = tcx.erase_regions(existential_trait_ref);
289-
290282
// Count number of methods preceding the one we are selecting and
291283
// add them to the total offset.
292284
if let Some(index) = tcx
293-
.own_existential_vtable_entries(existential_trait_ref)
285+
.own_existential_vtable_entries(object.upcast_trait_ref.def_id())
294286
.iter()
295287
.copied()
296288
.position(|def_id| def_id == method_def_id)

0 commit comments

Comments
 (0)