@@ -2465,17 +2465,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2465
2465
} ;
2466
2466
2467
2467
self . check_argument_types ( sp, & err_inputs[ ..] , & [ ] , args_no_rcvr,
2468
- false , tuple_arguments) ;
2468
+ false , tuple_arguments, None ) ;
2469
2469
self . tcx . types . err
2470
2470
} else {
2471
2471
match method_fn_ty. sty {
2472
- ty:: TyFnDef ( .., ref fty) => {
2472
+ ty:: TyFnDef ( def_id , .., ref fty) => {
2473
2473
// HACK(eddyb) ignore self in the definition (see above).
2474
2474
let expected_arg_tys = self . expected_types_for_fn_args ( sp, expected,
2475
2475
fty. sig . 0 . output ,
2476
2476
& fty. sig . 0 . inputs [ 1 ..] ) ;
2477
+
2477
2478
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) ) ;
2479
2481
fty. sig . 0 . output
2480
2482
}
2481
2483
_ => {
@@ -2493,7 +2495,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2493
2495
expected_arg_tys : & [ Ty < ' tcx > ] ,
2494
2496
args : & ' gcx [ hir:: Expr ] ,
2495
2497
variadic : bool ,
2496
- tuple_arguments : TupleArgumentsFlag ) {
2498
+ tuple_arguments : TupleArgumentsFlag ,
2499
+ def_span : Option < Span > ) {
2497
2500
let tcx = self . tcx ;
2498
2501
2499
2502
// Grab the argument types, supplying fresh type variables
@@ -2528,9 +2531,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2528
2531
sp
2529
2532
} ;
2530
2533
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 > ) {
2534
2537
let mut err = sess. struct_span_err_with_code ( sp,
2535
2538
& format ! ( "this function takes {}{} parameter{} but {} parameter{} supplied" ,
2536
2539
if variadic { "at least " } else { "" } ,
@@ -2540,18 +2543,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2540
2543
if arg_count == 1 { " was" } else { "s were" } ) ,
2541
2544
error_code) ;
2542
2545
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" ) ) ;
2555
2552
}
2556
2553
err. emit ( ) ;
2557
2554
}
@@ -2560,8 +2557,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2560
2557
let tuple_type = self . structurally_resolved_type ( sp, fn_inputs[ 0 ] ) ;
2561
2558
match tuple_type. sty {
2562
2559
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 ) ;
2565
2562
expected_arg_tys = & [ ] ;
2566
2563
self . err_args ( args. len ( ) )
2567
2564
}
@@ -2589,14 +2586,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2589
2586
if supplied_arg_count >= expected_arg_count {
2590
2587
fn_inputs. to_vec ( )
2591
2588
} 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 ) ;
2594
2591
expected_arg_tys = & [ ] ;
2595
2592
self . err_args ( supplied_arg_count)
2596
2593
}
2597
2594
} 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 ) ;
2600
2597
expected_arg_tys = & [ ] ;
2601
2598
self . err_args ( supplied_arg_count)
2602
2599
} ;
0 commit comments