@@ -14,6 +14,8 @@ use super::check_argument_types;
1414use super :: check_expr;
1515use super :: check_method_argument_types;
1616use super :: err_args;
17+ use super :: Expectation ;
18+ use super :: expected_types_for_fn_args;
1719use super :: FnCtxt ;
1820use super :: LvaluePreference ;
1921use super :: method;
@@ -65,7 +67,8 @@ pub fn check_legal_trait_for_method_call(ccx: &CrateCtxt, span: Span, trait_id:
6567pub fn check_call < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
6668 call_expr : & ast:: Expr ,
6769 callee_expr : & ast:: Expr ,
68- arg_exprs : & [ P < ast:: Expr > ] )
70+ arg_exprs : & [ P < ast:: Expr > ] ,
71+ expected : Expectation < ' tcx > )
6972{
7073 check_expr ( fcx, callee_expr) ;
7174 let original_callee_ty = fcx. expr_ty ( callee_expr) ;
@@ -84,15 +87,15 @@ pub fn check_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
8487 match result {
8588 None => {
8689 // this will report an error since original_callee_ty is not a fn
87- confirm_builtin_call ( fcx, call_expr, original_callee_ty, arg_exprs) ;
90+ confirm_builtin_call ( fcx, call_expr, original_callee_ty, arg_exprs, expected ) ;
8891 }
8992
9093 Some ( CallStep :: Builtin ) => {
91- confirm_builtin_call ( fcx, call_expr, callee_ty, arg_exprs) ;
94+ confirm_builtin_call ( fcx, call_expr, callee_ty, arg_exprs, expected ) ;
9295 }
9396
9497 Some ( CallStep :: Overloaded ( method_callee) ) => {
95- confirm_overloaded_call ( fcx, call_expr, arg_exprs, method_callee) ;
98+ confirm_overloaded_call ( fcx, call_expr, arg_exprs, method_callee, expected ) ;
9699 }
97100 }
98101}
@@ -153,7 +156,8 @@ fn try_overloaded_call_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
153156fn confirm_builtin_call < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
154157 call_expr : & ast:: Expr ,
155158 callee_ty : Ty < ' tcx > ,
156- arg_exprs : & [ P < ast:: Expr > ] )
159+ arg_exprs : & [ P < ast:: Expr > ] ,
160+ expected : Expectation < ' tcx > )
157161{
158162 let error_fn_sig;
159163
@@ -192,11 +196,16 @@ fn confirm_builtin_call<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
192196 fcx. normalize_associated_types_in ( call_expr. span , & fn_sig) ;
193197
194198 // Call the generic checker.
195- let arg_exprs: Vec < _ > = arg_exprs. iter ( ) . collect ( ) ; // for some weird reason we take &[&P<...>].
199+ let expected_arg_tys = expected_types_for_fn_args ( fcx,
200+ call_expr. span ,
201+ expected,
202+ fn_sig. output ,
203+ fn_sig. inputs . as_slice ( ) ) ;
196204 check_argument_types ( fcx,
197205 call_expr. span ,
198206 fn_sig. inputs . as_slice ( ) ,
199- arg_exprs. as_slice ( ) ,
207+ & expected_arg_tys[ ] ,
208+ arg_exprs,
200209 AutorefArgs :: No ,
201210 fn_sig. variadic ,
202211 TupleArgumentsFlag :: DontTupleArguments ) ;
@@ -207,16 +216,17 @@ fn confirm_builtin_call<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
207216fn confirm_overloaded_call < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
208217 call_expr : & ast:: Expr ,
209218 arg_exprs : & [ P < ast:: Expr > ] ,
210- method_callee : ty:: MethodCallee < ' tcx > )
219+ method_callee : ty:: MethodCallee < ' tcx > ,
220+ expected : Expectation < ' tcx > )
211221{
212- let arg_exprs: Vec < _ > = arg_exprs. iter ( ) . collect ( ) ; // for some weird reason we take &[&P<...>].
213222 let output_type = check_method_argument_types ( fcx,
214223 call_expr. span ,
215224 method_callee. ty ,
216225 call_expr,
217- arg_exprs. as_slice ( ) ,
226+ arg_exprs,
218227 AutorefArgs :: No ,
219- TupleArgumentsFlag :: TupleArguments ) ;
228+ TupleArgumentsFlag :: TupleArguments ,
229+ expected) ;
220230 let method_call = ty:: MethodCall :: expr ( call_expr. id ) ;
221231 fcx. inh . method_map . borrow_mut ( ) . insert ( method_call, method_callee) ;
222232 write_call ( fcx, call_expr, output_type) ;
0 commit comments