@@ -11,13 +11,16 @@ use crate::check::Expectation::{self, NoExpectation, ExpectHasType, ExpectCastab
1111use crate :: check:: fatally_break_rust;
1212use crate :: check:: report_unexpected_variant_res;
1313use crate :: check:: Needs ;
14+ use crate :: check:: TupleArgumentsFlag :: DontTupleArguments ;
15+ use crate :: check:: method:: SelfSource ;
1416use crate :: middle:: lang_items;
1517use crate :: util:: common:: ErrorReported ;
1618
1719use errors:: Applicability ;
1820use syntax:: ast;
1921use syntax:: ptr:: P ;
20- use syntax:: symbol:: sym;
22+ use syntax:: symbol:: { kw, sym} ;
23+ use syntax:: source_map:: Span ;
2124use rustc:: hir;
2225use rustc:: hir:: { ExprKind , QPath } ;
2326use rustc:: hir:: def:: { CtorKind , Res , DefKind } ;
@@ -772,6 +775,52 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
772775 ctxt. coerce . map ( |c| c. complete ( self ) ) . unwrap_or_else ( || self . tcx . mk_unit ( ) )
773776 }
774777
778+ /// Checks a method call.
779+ fn check_method_call (
780+ & self ,
781+ expr : & ' tcx hir:: Expr ,
782+ segment : & hir:: PathSegment ,
783+ span : Span ,
784+ args : & ' tcx [ hir:: Expr ] ,
785+ expected : Expectation < ' tcx > ,
786+ needs : Needs ,
787+ ) -> Ty < ' tcx > {
788+ let rcvr = & args[ 0 ] ;
789+ let rcvr_t = self . check_expr_with_needs ( & rcvr, needs) ;
790+ // no need to check for bot/err -- callee does that
791+ let rcvr_t = self . structurally_resolved_type ( args[ 0 ] . span , rcvr_t) ;
792+
793+ let method = match self . lookup_method ( rcvr_t,
794+ segment,
795+ span,
796+ expr,
797+ rcvr) {
798+ Ok ( method) => {
799+ self . write_method_call ( expr. hir_id , method) ;
800+ Ok ( method)
801+ }
802+ Err ( error) => {
803+ if segment. ident . name != kw:: Invalid {
804+ self . report_method_error ( span,
805+ rcvr_t,
806+ segment. ident ,
807+ SelfSource :: MethodCall ( rcvr) ,
808+ error,
809+ Some ( args) ) ;
810+ }
811+ Err ( ( ) )
812+ }
813+ } ;
814+
815+ // Call the generic checker.
816+ self . check_method_argument_types ( span,
817+ expr. span ,
818+ method,
819+ & args[ 1 ..] ,
820+ DontTupleArguments ,
821+ expected)
822+ }
823+
775824 fn check_expr_cast (
776825 & self ,
777826 e : & ' tcx hir:: Expr ,
0 commit comments