Skip to content

Commit 0fe86aa

Browse files
committed
Let mk_fn_def take an iterator instead to simplify some call sites
1 parent 7fd9bee commit 0fe86aa

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

compiler/rustc_middle/src/ty/adjustment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'tcx> OverloadedDeref<'tcx> {
131131
.find(|m| m.kind == ty::AssocKind::Fn)
132132
.unwrap()
133133
.def_id;
134-
tcx.mk_fn_def(method_def_id, tcx.mk_substs_trait(source, []))
134+
tcx.mk_fn_def(method_def_id, [source])
135135
}
136136
}
137137

compiler/rustc_middle/src/ty/context.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,12 +2565,20 @@ impl<'tcx> TyCtxt<'tcx> {
25652565
}
25662566

25672567
#[inline]
2568-
pub fn mk_fn_def(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
2568+
pub fn mk_fn_def(
2569+
self,
2570+
def_id: DefId,
2571+
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
2572+
) -> Ty<'tcx> {
2573+
let substs = substs.into_iter().map(Into::into);
2574+
let n = self.generics_of(def_id).count();
25692575
debug_assert_eq!(
2570-
self.generics_of(def_id).count(),
2571-
substs.len(),
2572-
"wrong number of generic parameters for {def_id:?}: {substs:?}",
2576+
(n, Some(n)),
2577+
substs.size_hint(),
2578+
"wrong number of generic parameters for {def_id:?}: {:?} \nDid you accidentally include the self-type in the params list?",
2579+
substs.collect::<Vec<_>>(),
25732580
);
2581+
let substs = self.mk_substs(substs);
25742582
self.mk_ty(FnDef(def_id, substs))
25752583
}
25762584

compiler/rustc_mir_build/src/build/matches/test.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,6 @@ fn trait_method<'tcx>(
838838
method_name: Symbol,
839839
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
840840
) -> ConstantKind<'tcx> {
841-
let substs = tcx.mk_substs(substs.into_iter().map(Into::into));
842-
843841
// The unhygienic comparison here is acceptable because this is only
844842
// used on known traits.
845843
let item = tcx

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,8 @@ impl<'tcx> CloneShimBuilder<'tcx> {
417417
) {
418418
let tcx = self.tcx;
419419

420-
let substs = tcx.mk_substs_trait(ty, []);
421-
422420
// `func == Clone::clone(&ty) -> ty`
423-
let func_ty = tcx.mk_fn_def(self.def_id, substs);
421+
let func_ty = tcx.mk_fn_def(self.def_id, [ty]);
424422
let func = Operand::Constant(Box::new(Constant {
425423
span: self.span,
426424
user_ty: None,

0 commit comments

Comments
 (0)