]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/check/method/confirm.rs
Move generic arg / param validation to `create_substs_for_generic_args`
[rust.git] / src / librustc_typeck / check / method / confirm.rs
index eee9dc99d35b473cbbb65a35ca227d7f0b97f32d..e3fde9159cc38257993f2941dd70faa7cdcbc012 100644 (file)
@@ -4,14 +4,14 @@
 use crate::check::{callee, FnCtxt, Needs, PlaceOp};
 use crate::hir::def_id::DefId;
 use crate::hir::GenericArg;
-use rustc::infer::{self, InferOk};
-use rustc::traits;
 use rustc::ty::adjustment::{Adjust, Adjustment, OverloadedDeref, PointerCast};
 use rustc::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
 use rustc::ty::fold::TypeFoldable;
 use rustc::ty::subst::{Subst, SubstsRef};
 use rustc::ty::{self, GenericParamDefKind, Ty};
 use rustc_hir as hir;
+use rustc_infer::infer::{self, InferOk};
+use rustc_infer::traits;
 use rustc_span::Span;
 
 use std::ops::Deref;
@@ -299,7 +299,7 @@ fn instantiate_method_substs(
         // If they were not explicitly supplied, just construct fresh
         // variables.
         let generics = self.tcx.generics_of(pick.item.def_id);
-        AstConv::check_generic_arg_count_for_call(
+        let arg_count_mismatch = AstConv::check_generic_arg_count_for_call(
             self.tcx, self.span, &generics, &seg, true, // `is_method_call`
         );
 
@@ -313,10 +313,16 @@ fn instantiate_method_substs(
             parent_substs,
             false,
             None,
+            arg_count_mismatch,
             // Provide the generic args, and whether types should be inferred.
-            |_| {
-                // The last argument of the returned tuple here is unimportant.
-                if let Some(ref data) = seg.args { (Some(data), false) } else { (None, false) }
+            |def_id| {
+                // The last component of the returned tuple here is unimportant.
+                if def_id == pick.item.def_id {
+                    if let Some(ref data) = seg.args {
+                        return (Some(data), false);
+                    }
+                }
+                (None, false)
             },
             // Provide substitutions for parameters for which (valid) arguments have been provided.
             |param, arg| match (&param.kind, arg) {