@@ -2465,17 +2465,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
24652465 } ;
24662466
24672467 self . check_argument_types ( sp, & err_inputs[ ..] , & [ ] , args_no_rcvr,
2468- false , tuple_arguments) ;
2468+ false , tuple_arguments, None ) ;
24692469 self . tcx . types . err
24702470 } else {
24712471 match method_fn_ty. sty {
2472- ty:: TyFnDef ( .., ref fty) => {
2472+ ty:: TyFnDef ( def_id , .., ref fty) => {
24732473 // HACK(eddyb) ignore self in the definition (see above).
24742474 let expected_arg_tys = self . expected_types_for_fn_args ( sp, expected,
24752475 fty. sig . 0 . output ,
24762476 & fty. sig . 0 . inputs [ 1 ..] ) ;
2477+
24772478 self . check_argument_types ( sp, & fty. sig . 0 . inputs [ 1 ..] , & expected_arg_tys[ ..] ,
2478- args_no_rcvr, fty. sig . 0 . variadic , tuple_arguments) ;
2479+ args_no_rcvr, fty. sig . 0 . variadic , tuple_arguments,
2480+ self . tcx . map . span_if_local ( def_id) ) ;
24792481 fty. sig . 0 . output
24802482 }
24812483 _ => {
@@ -2493,7 +2495,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
24932495 expected_arg_tys : & [ Ty < ' tcx > ] ,
24942496 args : & ' gcx [ hir:: Expr ] ,
24952497 variadic : bool ,
2496- tuple_arguments : TupleArgumentsFlag ) {
2498+ tuple_arguments : TupleArgumentsFlag ,
2499+ def_span : Option < Span > ) {
24972500 let tcx = self . tcx ;
24982501
24992502 // Grab the argument types, supplying fresh type variables
@@ -2528,9 +2531,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
25282531 sp
25292532 } ;
25302533
2531- fn parameter_count_error < ' tcx > ( sess : & Session , sp : Span , fn_inputs : & [ Ty < ' tcx > ] ,
2532- expected_count : usize , arg_count : usize , error_code : & str ,
2533- variadic : bool ) {
2534+ fn parameter_count_error < ' tcx > ( sess : & Session , sp : Span , expected_count : usize ,
2535+ arg_count : usize , error_code : & str , variadic : bool ,
2536+ def_span : Option < Span > ) {
25342537 let mut err = sess. struct_span_err_with_code ( sp,
25352538 & format ! ( "this function takes {}{} parameter{} but {} parameter{} supplied" ,
25362539 if variadic { "at least " } else { "" } ,
@@ -2540,18 +2543,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
25402543 if arg_count == 1 { " was" } else { "s were" } ) ,
25412544 error_code) ;
25422545
2543- let input_types = fn_inputs. iter ( ) . map ( |i| format ! ( "{:?}" , i) ) . collect :: < Vec < String > > ( ) ;
2544- if input_types. len ( ) > 1 {
2545- err. note ( "the following parameter types were expected:" ) ;
2546- err. note ( & input_types. join ( ", " ) ) ;
2547- } else if input_types. len ( ) > 0 {
2548- err. note ( & format ! ( "the following parameter type was expected: {}" ,
2549- input_types[ 0 ] ) ) ;
2550- } else {
2551- err. span_label ( sp, & format ! ( "expected {}{} parameter{}" ,
2552- if variadic { "at least " } else { "" } ,
2553- expected_count,
2554- if expected_count == 1 { "" } else { "s" } ) ) ;
2546+ err. span_label ( sp, & format ! ( "expected {}{} parameter{}" ,
2547+ if variadic { "at least " } else { "" } ,
2548+ expected_count,
2549+ if expected_count == 1 { "" } else { "s" } ) ) ;
2550+ if let Some ( def_s) = def_span {
2551+ err. span_label ( def_s, & format ! ( "defined here" ) ) ;
25552552 }
25562553 err. emit ( ) ;
25572554 }
@@ -2560,8 +2557,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
25602557 let tuple_type = self . structurally_resolved_type ( sp, fn_inputs[ 0 ] ) ;
25612558 match tuple_type. sty {
25622559 ty:: TyTuple ( arg_types) if arg_types. len ( ) != args. len ( ) => {
2563- parameter_count_error ( tcx. sess , sp_args, fn_inputs , arg_types. len ( ) , args. len ( ) ,
2564- "E0057" , false ) ;
2560+ parameter_count_error ( tcx. sess , sp_args, arg_types. len ( ) , args. len ( ) ,
2561+ "E0057" , false , def_span ) ;
25652562 expected_arg_tys = & [ ] ;
25662563 self . err_args ( args. len ( ) )
25672564 }
@@ -2589,14 +2586,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
25892586 if supplied_arg_count >= expected_arg_count {
25902587 fn_inputs. to_vec ( )
25912588 } else {
2592- parameter_count_error ( tcx. sess , sp_args, fn_inputs , expected_arg_count,
2593- supplied_arg_count, "E0060" , true ) ;
2589+ parameter_count_error ( tcx. sess , sp_args, expected_arg_count,
2590+ supplied_arg_count, "E0060" , true , def_span ) ;
25942591 expected_arg_tys = & [ ] ;
25952592 self . err_args ( supplied_arg_count)
25962593 }
25972594 } else {
2598- parameter_count_error ( tcx. sess , sp_args, fn_inputs , expected_arg_count,
2599- supplied_arg_count, "E0061" , false ) ;
2595+ parameter_count_error ( tcx. sess , sp_args, expected_arg_count,
2596+ supplied_arg_count, "E0061" , false , def_span ) ;
26002597 expected_arg_tys = & [ ] ;
26012598 self . err_args ( supplied_arg_count)
26022599 } ;
0 commit comments