Simplify an ObjectData field

This commit is contained in:
Michael Goulet 2023-06-16 00:48:29 +00:00
parent 9e68b6f505
commit 1311bb56f3
4 changed files with 14 additions and 10 deletions

View File

@ -653,7 +653,7 @@ pub enum ImplSource<'tcx, N> {
Param(Vec<N>, ty::BoundConstness),
/// Virtual calls through an object.
Object(ImplSourceObjectData<'tcx, N>),
Object(ImplSourceObjectData<N>),
/// Successful resolution for a builtin trait.
Builtin(Vec<N>),
@ -735,7 +735,7 @@ pub fn map<M, F>(self, f: F) -> ImplSource<'tcx, M>
ImplSource::Param(n, ct) => ImplSource::Param(n.into_iter().map(f).collect(), ct),
ImplSource::Builtin(n) => ImplSource::Builtin(n.into_iter().map(f).collect()),
ImplSource::Object(o) => ImplSource::Object(ImplSourceObjectData {
upcast_trait_ref: o.upcast_trait_ref,
upcast_trait_def_id: o.upcast_trait_def_id,
vtable_base: o.vtable_base,
nested: o.nested.into_iter().map(f).collect(),
}),
@ -835,9 +835,9 @@ pub struct ImplSourceTraitUpcastingData<N> {
#[derive(PartialEq, Eq, Clone, TyEncodable, TyDecodable, HashStable, Lift)]
#[derive(TypeFoldable, TypeVisitable)]
pub struct ImplSourceObjectData<'tcx, N> {
pub struct ImplSourceObjectData<N> {
/// `Foo` upcast to the obligation trait. This will be some supertrait of `Foo`.
pub upcast_trait_ref: ty::PolyTraitRef<'tcx>,
pub upcast_trait_def_id: DefId,
/// The vtable is formed by concatenating together the method lists of
/// the base object trait and all supertraits, pointers to supertrait vtable will

View File

@ -82,12 +82,12 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
}
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceObjectData<'tcx, N> {
impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceObjectData<N> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"ImplSourceObjectData(upcast={:?}, vtable_base={}, nested={:?})",
self.upcast_trait_ref, self.vtable_base, self.nested
self.upcast_trait_def_id, self.vtable_base, self.nested
)
}
}

View File

@ -486,7 +486,7 @@ fn confirm_object_candidate(
&mut self,
obligation: &TraitObligation<'tcx>,
index: usize,
) -> Result<ImplSourceObjectData<'tcx, PredicateObligation<'tcx>>, SelectionError<'tcx>> {
) -> Result<ImplSourceObjectData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
let tcx = self.tcx();
debug!(?obligation, ?index, "confirm_object_candidate");
@ -653,7 +653,11 @@ fn confirm_object_candidate(
(unnormalized_upcast_trait_ref, ty::Binder::dummy(object_trait_ref)),
);
Ok(ImplSourceObjectData { upcast_trait_ref, vtable_base, nested })
Ok(ImplSourceObjectData {
upcast_trait_def_id: upcast_trait_ref.def_id(),
vtable_base,
nested,
})
}
fn confirm_fn_pointer_candidate(

View File

@ -243,12 +243,12 @@ pub fn upcast_choices<'tcx>(
/// `object.upcast_trait_ref`) within the vtable for `object`.
pub fn get_vtable_index_of_object_method<'tcx, N>(
tcx: TyCtxt<'tcx>,
object: &super::ImplSourceObjectData<'tcx, N>,
object: &super::ImplSourceObjectData<N>,
method_def_id: DefId,
) -> Option<usize> {
// Count number of methods preceding the one we are selecting and
// add them to the total offset.
tcx.own_existential_vtable_entries(object.upcast_trait_ref.def_id())
tcx.own_existential_vtable_entries(object.upcast_trait_def_id)
.iter()
.copied()
.position(|def_id| def_id == method_def_id)