@@ -11,13 +11,16 @@ use crate::check::Expectation::{self, NoExpectation, ExpectHasType, ExpectCastab
11
11
use crate :: check:: fatally_break_rust;
12
12
use crate :: check:: report_unexpected_variant_res;
13
13
use crate :: check:: Needs ;
14
+ use crate :: check:: TupleArgumentsFlag :: DontTupleArguments ;
15
+ use crate :: check:: method:: SelfSource ;
14
16
use crate :: middle:: lang_items;
15
17
use crate :: util:: common:: ErrorReported ;
16
18
17
19
use errors:: Applicability ;
18
20
use syntax:: ast;
19
21
use syntax:: ptr:: P ;
20
- use syntax:: symbol:: sym;
22
+ use syntax:: symbol:: { kw, sym} ;
23
+ use syntax:: source_map:: Span ;
21
24
use rustc:: hir;
22
25
use rustc:: hir:: { ExprKind , QPath } ;
23
26
use rustc:: hir:: def:: { CtorKind , Res , DefKind } ;
@@ -772,6 +775,52 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
772
775
ctxt. coerce . map ( |c| c. complete ( self ) ) . unwrap_or_else ( || self . tcx . mk_unit ( ) )
773
776
}
774
777
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
+
775
824
fn check_expr_cast (
776
825
& self ,
777
826
e : & ' tcx hir:: Expr ,
0 commit comments