@@ -14,7 +14,7 @@ use rustc_middle::ty::adjustment::{
1414use rustc_middle:: ty:: { self , GenericArgsRef , Ty , TyCtxt , TypeVisitableExt } ;
1515use rustc_middle:: { bug, span_bug} ;
1616use rustc_span:: def_id:: LocalDefId ;
17- use rustc_span:: { Ident , Span , sym} ;
17+ use rustc_span:: { Span , sym} ;
1818use rustc_trait_selection:: error_reporting:: traits:: DefIdOrName ;
1919use rustc_trait_selection:: infer:: InferCtxtExt as _;
2020use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
@@ -87,14 +87,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8787
8888 let output = match result {
8989 None => {
90- // this will report an error since original_callee_ty is not a fn
91- self . confirm_builtin_call (
92- call_expr,
93- callee_expr,
94- original_callee_ty,
95- arg_exprs,
96- expected,
97- )
90+ // Check all of the arg expressions, but with no expectations
91+ // since we don't have a signature to compare them to.
92+ for arg in arg_exprs {
93+ self . check_expr ( arg) ;
94+ }
95+
96+ if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, path) ) = & callee_expr. kind
97+ && let [ segment] = path. segments
98+ {
99+ self . dcx ( ) . try_steal_modify_and_emit_err (
100+ segment. ident . span ,
101+ StashKey :: CallIntoMethod ,
102+ |err| {
103+ // Try suggesting `foo(a)` -> `a.foo()` if possible.
104+ self . suggest_call_as_method (
105+ err, segment, arg_exprs, call_expr, expected,
106+ ) ;
107+ } ,
108+ ) ;
109+ }
110+
111+ let guar = self . report_invalid_callee ( call_expr, callee_expr, expr_ty, arg_exprs) ;
112+ Ty :: new_error ( self . tcx , guar)
98113 }
99114
100115 Some ( CallStep :: Builtin ( callee_ty) ) => {
@@ -296,9 +311,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
296311 Ty :: new_tup_from_iter ( self . tcx , arg_exprs. iter ( ) . map ( |e| self . next_ty_var ( e. span ) ) )
297312 } ) ;
298313
299- if let Some ( ok) = self . lookup_method_in_trait (
314+ if let Some ( ok) = self . lookup_method_for_operator (
300315 self . misc ( call_expr. span ) ,
301- Ident :: with_dummy_span ( method_name) ,
316+ method_name,
302317 trait_def_id,
303318 adjusted_ty,
304319 opt_input_type,
@@ -461,32 +476,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
461476 }
462477 ( fn_sig, Some ( def_id) )
463478 }
479+
464480 // FIXME(const_trait_impl): these arms should error because we can't enforce them
465481 ty:: FnPtr ( sig_tys, hdr) => ( sig_tys. with ( hdr) , None ) ,
466- _ => {
467- for arg in arg_exprs {
468- self . check_expr ( arg) ;
469- }
470482
471- if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, path) ) = & callee_expr. kind
472- && let [ segment] = path. segments
473- {
474- self . dcx ( ) . try_steal_modify_and_emit_err (
475- segment. ident . span ,
476- StashKey :: CallIntoMethod ,
477- |err| {
478- // Try suggesting `foo(a)` -> `a.foo()` if possible.
479- self . suggest_call_as_method (
480- err, segment, arg_exprs, call_expr, expected,
481- ) ;
482- } ,
483- ) ;
484- }
485-
486- let err = self . report_invalid_callee ( call_expr, callee_expr, callee_ty, arg_exprs) ;
487-
488- return Ty :: new_error ( self . tcx , err) ;
489- }
483+ _ => unreachable ! ( ) ,
490484 } ;
491485
492486 // Replace any late-bound regions that appear in the function
@@ -908,19 +902,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
908902 call_expr : & ' tcx hir:: Expr < ' tcx > ,
909903 arg_exprs : & ' tcx [ hir:: Expr < ' tcx > ] ,
910904 expected : Expectation < ' tcx > ,
911- method_callee : MethodCallee < ' tcx > ,
905+ method : MethodCallee < ' tcx > ,
912906 ) -> Ty < ' tcx > {
913- let output_type = self . check_method_argument_types (
907+ self . check_argument_types (
914908 call_expr. span ,
915909 call_expr,
916- Ok ( method_callee) ,
910+ & method. sig . inputs ( ) [ 1 ..] ,
911+ method. sig . output ( ) ,
912+ expected,
917913 arg_exprs,
914+ method. sig . c_variadic ,
918915 TupleArgumentsFlag :: TupleArguments ,
919- expected ,
916+ Some ( method . def_id ) ,
920917 ) ;
921918
922- self . write_method_call_and_enforce_effects ( call_expr. hir_id , call_expr. span , method_callee) ;
923- output_type
919+ self . write_method_call_and_enforce_effects ( call_expr. hir_id , call_expr. span , method) ;
920+
921+ method. sig . output ( )
924922 }
925923}
926924
0 commit comments