diff --git a/compiler/rustc_middle/src/ty/adjustment.rs b/compiler/rustc_middle/src/ty/adjustment.rs index 7036c4a7b27d..8ce06404de08 100644 --- a/compiler/rustc_middle/src/ty/adjustment.rs +++ b/compiler/rustc_middle/src/ty/adjustment.rs @@ -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]) } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index ad097b39d108..fc7bdb553525 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -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>>, + ) -> 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::>(), ); + let substs = self.mk_substs(substs); self.mk_ty(FnDef(def_id, substs)) } diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index 6d5a98342d29..de6a48f7cc41 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -838,8 +838,6 @@ fn trait_method<'tcx>( method_name: Symbol, substs: impl IntoIterator>>, ) -> 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 diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index f92a0e826dcd..ec84243fbeb8 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -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,