@@ -14,7 +14,7 @@ use rustc_middle::ty::adjustment::{
14
14
use rustc_middle:: ty:: { self , GenericArgsRef , Ty , TyCtxt , TypeVisitableExt } ;
15
15
use rustc_middle:: { bug, span_bug} ;
16
16
use rustc_span:: def_id:: LocalDefId ;
17
- use rustc_span:: { Ident , Span , sym} ;
17
+ use rustc_span:: { Span , sym} ;
18
18
use rustc_trait_selection:: error_reporting:: traits:: DefIdOrName ;
19
19
use rustc_trait_selection:: infer:: InferCtxtExt as _;
20
20
use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
@@ -87,14 +87,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
87
87
88
88
let output = match result {
89
89
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)
98
113
}
99
114
100
115
Some ( CallStep :: Builtin ( callee_ty) ) => {
@@ -296,9 +311,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
296
311
Ty :: new_tup_from_iter ( self . tcx , arg_exprs. iter ( ) . map ( |e| self . next_ty_var ( e. span ) ) )
297
312
} ) ;
298
313
299
- if let Some ( ok) = self . lookup_method_in_trait (
314
+ if let Some ( ok) = self . lookup_method_for_operator (
300
315
self . misc ( call_expr. span ) ,
301
- Ident :: with_dummy_span ( method_name) ,
316
+ method_name,
302
317
trait_def_id,
303
318
adjusted_ty,
304
319
opt_input_type,
@@ -461,32 +476,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
461
476
}
462
477
( fn_sig, Some ( def_id) )
463
478
}
479
+
464
480
// FIXME(const_trait_impl): these arms should error because we can't enforce them
465
481
ty:: FnPtr ( sig_tys, hdr) => ( sig_tys. with ( hdr) , None ) ,
466
- _ => {
467
- for arg in arg_exprs {
468
- self . check_expr ( arg) ;
469
- }
470
482
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 ! ( ) ,
490
484
} ;
491
485
492
486
// Replace any late-bound regions that appear in the function
@@ -908,19 +902,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
908
902
call_expr : & ' tcx hir:: Expr < ' tcx > ,
909
903
arg_exprs : & ' tcx [ hir:: Expr < ' tcx > ] ,
910
904
expected : Expectation < ' tcx > ,
911
- method_callee : MethodCallee < ' tcx > ,
905
+ method : MethodCallee < ' tcx > ,
912
906
) -> Ty < ' tcx > {
913
- let output_type = self . check_method_argument_types (
907
+ self . check_argument_types (
914
908
call_expr. span ,
915
909
call_expr,
916
- Ok ( method_callee) ,
910
+ & method. sig . inputs ( ) [ 1 ..] ,
911
+ method. sig . output ( ) ,
912
+ expected,
917
913
arg_exprs,
914
+ method. sig . c_variadic ,
918
915
TupleArgumentsFlag :: TupleArguments ,
919
- expected ,
916
+ Some ( method . def_id ) ,
920
917
) ;
921
918
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 ( )
924
922
}
925
923
}
926
924
0 commit comments