Let mk_fn_def take an iterator instead to simplify some call sites

This commit is contained in:
Oli Scherer 2022-12-13 10:37:19 +00:00
parent 7fd9beedc2
commit 0fe86aa977
4 changed files with 14 additions and 10 deletions

View file

@ -131,7 +131,7 @@ impl<'tcx> OverloadedDeref<'tcx> {
.find(|m| m.kind == ty::AssocKind::Fn)
.unwrap()
.def_id;
tcx.mk_fn_def(method_def_id, tcx.mk_substs_trait(source, []))
tcx.mk_fn_def(method_def_id, [source])
}
}

View file

@ -2565,12 +2565,20 @@ impl<'tcx> TyCtxt<'tcx> {
}
#[inline]
pub fn mk_fn_def(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
pub fn mk_fn_def(
self,
def_id: DefId,
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
) -> Ty<'tcx> {
let substs = substs.into_iter().map(Into::into);
let n = self.generics_of(def_id).count();
debug_assert_eq!(
self.generics_of(def_id).count(),
substs.len(),
"wrong number of generic parameters for {def_id:?}: {substs:?}",
(n, Some(n)),
substs.size_hint(),
"wrong number of generic parameters for {def_id:?}: {:?} \nDid you accidentally include the self-type in the params list?",
substs.collect::<Vec<_>>(),
);
let substs = self.mk_substs(substs);
self.mk_ty(FnDef(def_id, substs))
}

View file

@ -838,8 +838,6 @@ fn trait_method<'tcx>(
method_name: Symbol,
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
) -> ConstantKind<'tcx> {
let substs = tcx.mk_substs(substs.into_iter().map(Into::into));
// The unhygienic comparison here is acceptable because this is only
// used on known traits.
let item = tcx

View file

@ -417,10 +417,8 @@ impl<'tcx> CloneShimBuilder<'tcx> {
) {
let tcx = self.tcx;
let substs = tcx.mk_substs_trait(ty, []);
// `func == Clone::clone(&ty) -> ty`
let func_ty = tcx.mk_fn_def(self.def_id, substs);
let func_ty = tcx.mk_fn_def(self.def_id, [ty]);
let func = Operand::Constant(Box::new(Constant {
span: self.span,
user_ty: None,