1
Fork 0

Stop passing the self-type as a separate argument.

This commit is contained in:
Oli Scherer 2022-11-21 12:24:53 +00:00
parent a4da3f8863
commit 7658e0fccf
38 changed files with 113 additions and 164 deletions

View file

@ -2820,17 +2820,17 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn mk_trait_ref(
self,
trait_def_id: DefId,
self_ty: Ty<'tcx>,
rest: impl IntoIterator<Item = GenericArg<'tcx>, IntoIter: ExactSizeIterator>,
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
) -> ty::TraitRef<'tcx> {
let rest = rest.into_iter();
let substs = substs.into_iter().map(Into::into);
let n = self.generics_of(trait_def_id).count();
debug_assert_eq!(
self.generics_of(trait_def_id).count() - 1,
rest.len(),
"wrong number of generic parameters for {trait_def_id:?} on self type {self_ty:?}: {:?} \nDid you accidentally include the self-type in the params list?",
rest.collect::<Vec<_>>(),
(n, Some(n)),
substs.size_hint(),
"wrong number of generic parameters for {trait_def_id:?}: {:?} \nDid you accidentally include the self-type in the params list?",
substs.collect::<Vec<_>>(),
);
let substs = self.mk_substs_trait(self_ty, rest);
let substs = self.mk_substs(substs);
ty::TraitRef::new(trait_def_id, substs)
}
@ -2994,11 +2994,10 @@ impl<'tcx> TyCtxtAt<'tcx> {
pub fn mk_trait_ref(
self,
trait_lang_item: LangItem,
self_ty: Ty<'tcx>,
rest: impl IntoIterator<Item = ty::GenericArg<'tcx>, IntoIter: ExactSizeIterator>,
substs: impl IntoIterator<Item = impl Into<ty::GenericArg<'tcx>>>,
) -> ty::TraitRef<'tcx> {
let trait_def_id = self.require_lang_item(trait_lang_item, Some(self.span));
self.tcx.mk_trait_ref(trait_def_id, self_ty, rest)
self.tcx.mk_trait_ref(trait_def_id, substs)
}
}

View file

@ -719,7 +719,7 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
}
ExistentialPredicate::AutoTrait(did) => {
let trait_ref = self.rebind(tcx.mk_trait_ref(did, self_ty, []));
let trait_ref = self.rebind(tcx.mk_trait_ref(did, [self_ty]));
trait_ref.without_const().to_predicate(tcx)
}
}
@ -812,7 +812,10 @@ impl<'tcx> TraitRef<'tcx> {
}
pub fn with_self_type(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
tcx.mk_trait_ref(self.def_id, self_ty, self.substs.iter().skip(1))
tcx.mk_trait_ref(
self.def_id,
[self_ty.into()].into_iter().chain(self.substs.iter().skip(1)),
)
}
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
@ -910,7 +913,7 @@ impl<'tcx> ExistentialTraitRef<'tcx> {
// otherwise the escaping vars would be captured by the binder
// debug_assert!(!self_ty.has_escaping_bound_vars());
tcx.mk_trait_ref(self.def_id, self_ty, self.substs.iter())
tcx.mk_trait_ref(self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter()))
}
}