@@ -8,6 +8,7 @@ use hir::def_id::{DefId, LOCAL_CRATE};
8
8
use rustc:: ty:: adjustment:: { Adjust , Adjustment , AllowTwoPhase , AutoBorrow , AutoBorrowMutability } ;
9
9
use rustc:: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
10
10
use rustc:: { infer, traits} ;
11
+ use rustc:: infer:: type_variable:: TypeVariableOrigin ;
11
12
use rustc_target:: spec:: abi;
12
13
use syntax:: ast:: Ident ;
13
14
use syntax_pos:: Span ;
@@ -46,7 +47,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
46
47
let mut autoderef = self . autoderef ( callee_expr. span , expr_ty) ;
47
48
let mut result = None ;
48
49
while result. is_none ( ) && autoderef. next ( ) . is_some ( ) {
49
- result = self . try_overloaded_call_step ( call_expr, callee_expr, & autoderef) ;
50
+ result = self . try_overloaded_call_step ( call_expr, callee_expr, arg_exprs , & autoderef) ;
50
51
}
51
52
autoderef. finalize ( self ) ;
52
53
@@ -79,6 +80,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
79
80
& self ,
80
81
call_expr : & ' gcx hir:: Expr ,
81
82
callee_expr : & ' gcx hir:: Expr ,
83
+ arg_exprs : & ' gcx [ hir:: Expr ] ,
82
84
autoderef : & Autoderef < ' a , ' gcx , ' tcx > ,
83
85
) -> Option < CallStep < ' tcx > > {
84
86
let adjusted_ty = autoderef. unambiguous_final_ty ( self ) ;
@@ -142,7 +144,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
142
144
_ => { }
143
145
}
144
146
145
- self . try_overloaded_call_traits ( call_expr, adjusted_ty)
147
+ self . try_overloaded_call_traits ( call_expr, adjusted_ty, Some ( arg_exprs ) )
146
148
. map ( |( autoref, method) | {
147
149
let mut adjustments = autoderef. adjust_steps ( self , Needs :: None ) ;
148
150
adjustments. extend ( autoref) ;
@@ -155,6 +157,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
155
157
& self ,
156
158
call_expr : & hir:: Expr ,
157
159
adjusted_ty : Ty < ' tcx > ,
160
+ opt_arg_exprs : Option < & ' gcx [ hir:: Expr ] > ,
158
161
) -> Option < ( Option < Adjustment < ' tcx > > , MethodCallee < ' tcx > ) > {
159
162
// Try the options that are least restrictive on the caller first.
160
163
for & ( opt_trait_def_id, method_name, borrow) in & [
@@ -179,12 +182,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
179
182
None => continue ,
180
183
} ;
181
184
185
+ let opt_input_types = opt_arg_exprs. map ( |arg_exprs| [ self . tcx . mk_tup (
186
+ arg_exprs
187
+ . iter ( )
188
+ . map ( |e| self . next_ty_var (
189
+ TypeVariableOrigin :: TypeInference ( e. span )
190
+ ) )
191
+ ) ] ) ;
192
+ let opt_input_types = opt_input_types. as_ref ( ) . map ( AsRef :: as_ref) ;
193
+
182
194
if let Some ( ok) = self . lookup_method_in_trait (
183
195
call_expr. span ,
184
196
method_name,
185
197
trait_def_id,
186
198
adjusted_ty,
187
- None ,
199
+ opt_input_types ,
188
200
) {
189
201
let method = self . register_infer_ok_obligations ( ok) ;
190
202
let mut autoref = None ;
@@ -445,7 +457,7 @@ impl<'a, 'gcx, 'tcx> DeferredCallResolution<'gcx, 'tcx> {
445
457
. is_some( ) ) ;
446
458
447
459
// We may now know enough to figure out fn vs fnmut etc.
448
- match fcx. try_overloaded_call_traits ( self . call_expr , self . adjusted_ty ) {
460
+ match fcx. try_overloaded_call_traits ( self . call_expr , self . adjusted_ty , None ) {
449
461
Some ( ( autoref, method_callee) ) => {
450
462
// One problem is that when we get here, we are going
451
463
// to have a newly instantiated function signature
0 commit comments