@@ -2467,17 +2467,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2467
2467
} ;
2468
2468
2469
2469
self . check_argument_types ( sp, & err_inputs[ ..] , & [ ] , args_no_rcvr,
2470
- false , tuple_arguments) ;
2470
+ false , tuple_arguments, None ) ;
2471
2471
self . tcx . types . err
2472
2472
} else {
2473
2473
match method_fn_ty. sty {
2474
- ty:: TyFnDef ( .., ref fty) => {
2474
+ ty:: TyFnDef ( def_id , .., ref fty) => {
2475
2475
// HACK(eddyb) ignore self in the definition (see above).
2476
2476
let expected_arg_tys = self . expected_types_for_fn_args ( sp, expected,
2477
2477
fty. sig . 0 . output ,
2478
2478
& fty. sig . 0 . inputs [ 1 ..] ) ;
2479
+
2479
2480
self . check_argument_types ( sp, & fty. sig . 0 . inputs [ 1 ..] , & expected_arg_tys[ ..] ,
2480
- args_no_rcvr, fty. sig . 0 . variadic , tuple_arguments) ;
2481
+ args_no_rcvr, fty. sig . 0 . variadic , tuple_arguments,
2482
+ self . tcx . map . span_if_local ( def_id) ) ;
2481
2483
fty. sig . 0 . output
2482
2484
}
2483
2485
_ => {
@@ -2495,7 +2497,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2495
2497
expected_arg_tys : & [ Ty < ' tcx > ] ,
2496
2498
args : & ' gcx [ hir:: Expr ] ,
2497
2499
variadic : bool ,
2498
- tuple_arguments : TupleArgumentsFlag ) {
2500
+ tuple_arguments : TupleArgumentsFlag ,
2501
+ def_span : Option < Span > ) {
2499
2502
let tcx = self . tcx ;
2500
2503
2501
2504
// Grab the argument types, supplying fresh type variables
@@ -2530,9 +2533,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2530
2533
sp
2531
2534
} ;
2532
2535
2533
- fn parameter_count_error < ' tcx > ( sess : & Session , sp : Span , fn_inputs : & [ Ty < ' tcx > ] ,
2534
- expected_count : usize , arg_count : usize , error_code : & str ,
2535
- variadic : bool ) {
2536
+ fn parameter_count_error < ' tcx > ( sess : & Session , sp : Span , expected_count : usize ,
2537
+ arg_count : usize , error_code : & str , variadic : bool ,
2538
+ def_span : Option < Span > ) {
2536
2539
let mut err = sess. struct_span_err_with_code ( sp,
2537
2540
& format ! ( "this function takes {}{} parameter{} but {} parameter{} supplied" ,
2538
2541
if variadic { "at least " } else { "" } ,
@@ -2542,18 +2545,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2542
2545
if arg_count == 1 { " was" } else { "s were" } ) ,
2543
2546
error_code) ;
2544
2547
2545
- let input_types = fn_inputs. iter ( ) . map ( |i| format ! ( "{:?}" , i) ) . collect :: < Vec < String > > ( ) ;
2546
- if input_types. len ( ) > 1 {
2547
- err. note ( "the following parameter types were expected:" ) ;
2548
- err. note ( & input_types. join ( ", " ) ) ;
2549
- } else if input_types. len ( ) > 0 {
2550
- err. note ( & format ! ( "the following parameter type was expected: {}" ,
2551
- input_types[ 0 ] ) ) ;
2552
- } else {
2553
- err. span_label ( sp, & format ! ( "expected {}{} parameter{}" ,
2554
- if variadic { "at least " } else { "" } ,
2555
- expected_count,
2556
- if expected_count == 1 { "" } else { "s" } ) ) ;
2548
+ err. span_label ( sp, & format ! ( "expected {}{} parameter{}" ,
2549
+ if variadic { "at least " } else { "" } ,
2550
+ expected_count,
2551
+ if expected_count == 1 { "" } else { "s" } ) ) ;
2552
+ if let Some ( def_s) = def_span {
2553
+ err. span_label ( def_s, & format ! ( "defined here" ) ) ;
2557
2554
}
2558
2555
err. emit ( ) ;
2559
2556
}
@@ -2562,8 +2559,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2562
2559
let tuple_type = self . structurally_resolved_type ( sp, fn_inputs[ 0 ] ) ;
2563
2560
match tuple_type. sty {
2564
2561
ty:: TyTuple ( arg_types) if arg_types. len ( ) != args. len ( ) => {
2565
- parameter_count_error ( tcx. sess , sp_args, fn_inputs , arg_types. len ( ) , args. len ( ) ,
2566
- "E0057" , false ) ;
2562
+ parameter_count_error ( tcx. sess , sp_args, arg_types. len ( ) , args. len ( ) ,
2563
+ "E0057" , false , def_span ) ;
2567
2564
expected_arg_tys = & [ ] ;
2568
2565
self . err_args ( args. len ( ) )
2569
2566
}
@@ -2591,14 +2588,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2591
2588
if supplied_arg_count >= expected_arg_count {
2592
2589
fn_inputs. to_vec ( )
2593
2590
} else {
2594
- parameter_count_error ( tcx. sess , sp_args, fn_inputs , expected_arg_count,
2595
- supplied_arg_count, "E0060" , true ) ;
2591
+ parameter_count_error ( tcx. sess , sp_args, expected_arg_count,
2592
+ supplied_arg_count, "E0060" , true , def_span ) ;
2596
2593
expected_arg_tys = & [ ] ;
2597
2594
self . err_args ( supplied_arg_count)
2598
2595
}
2599
2596
} else {
2600
- parameter_count_error ( tcx. sess , sp_args, fn_inputs , expected_arg_count,
2601
- supplied_arg_count, "E0061" , false ) ;
2597
+ parameter_count_error ( tcx. sess , sp_args, expected_arg_count,
2598
+ supplied_arg_count, "E0061" , false , def_span ) ;
2602
2599
expected_arg_tys = & [ ] ;
2603
2600
self . err_args ( supplied_arg_count)
2604
2601
} ;
0 commit comments