@@ -2407,29 +2407,45 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2407
2407
2408
2408
let mut expected_arg_tys = expected_arg_tys;
2409
2409
let expected_arg_count = fn_inputs. len ( ) ;
2410
+
2411
+ fn parameter_count_error < ' tcx > ( sess : & Session , sp : Span , fn_inputs : & [ Ty < ' tcx > ] ,
2412
+ expected_count : usize , arg_count : usize , error_code : & str ,
2413
+ variadic : bool ) {
2414
+ let mut err = sess. struct_span_err_with_code ( sp,
2415
+ & format ! ( "this function takes {}{} parameter{} but {} parameter{} supplied" ,
2416
+ if variadic { "at least " } else { "" } ,
2417
+ expected_count,
2418
+ if expected_count == 1 { "" } else { "s" } ,
2419
+ arg_count,
2420
+ if arg_count == 1 { " was" } else { "s were" } ) ,
2421
+ error_code) ;
2422
+ let input_types = fn_inputs. iter ( ) . map ( |i| format ! ( "{:?}" , i) ) . collect :: < Vec < String > > ( ) ;
2423
+ if input_types. len ( ) > 0 {
2424
+ err. note ( & format ! ( "the following parameter type{} expected: {}" ,
2425
+ if expected_count == 1 { " was" } else { "s were" } ,
2426
+ input_types. join( ", " ) ) ) ;
2427
+ }
2428
+ err. emit ( ) ;
2429
+ }
2430
+
2410
2431
let formal_tys = if tuple_arguments == TupleArguments {
2411
2432
let tuple_type = self . structurally_resolved_type ( sp, fn_inputs[ 0 ] ) ;
2412
2433
match tuple_type. sty {
2434
+ ty:: TyTuple ( arg_types) if arg_types. len ( ) != args. len ( ) => {
2435
+ parameter_count_error ( tcx. sess , sp, fn_inputs, arg_types. len ( ) , args. len ( ) ,
2436
+ "E0057" , false ) ;
2437
+ expected_arg_tys = & [ ] ;
2438
+ self . err_args ( args. len ( ) )
2439
+ }
2413
2440
ty:: TyTuple ( arg_types) => {
2414
- if arg_types. len ( ) != args. len ( ) {
2415
- span_err ! ( tcx. sess, sp, E0057 ,
2416
- "this function takes {} parameter{} but {} parameter{} supplied" ,
2417
- arg_types. len( ) ,
2418
- if arg_types. len( ) == 1 { "" } else { "s" } ,
2419
- args. len( ) ,
2420
- if args. len( ) == 1 { " was" } else { "s were" } ) ;
2421
- expected_arg_tys = & [ ] ;
2422
- self . err_args ( args. len ( ) )
2423
- } else {
2424
- expected_arg_tys = match expected_arg_tys. get ( 0 ) {
2425
- Some ( & ty) => match ty. sty {
2426
- ty:: TyTuple ( ref tys) => & tys,
2427
- _ => & [ ]
2428
- } ,
2429
- None => & [ ]
2430
- } ;
2431
- arg_types. to_vec ( )
2432
- }
2441
+ expected_arg_tys = match expected_arg_tys. get ( 0 ) {
2442
+ Some ( & ty) => match ty. sty {
2443
+ ty:: TyTuple ( ref tys) => & tys,
2444
+ _ => & [ ]
2445
+ } ,
2446
+ None => & [ ]
2447
+ } ;
2448
+ arg_types. to_vec ( )
2433
2449
}
2434
2450
_ => {
2435
2451
span_err ! ( tcx. sess, sp, E0059 ,
@@ -2445,23 +2461,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2445
2461
if supplied_arg_count >= expected_arg_count {
2446
2462
fn_inputs. to_vec ( )
2447
2463
} else {
2448
- span_err ! ( tcx. sess, sp, E0060 ,
2449
- "this function takes at least {} parameter{} \
2450
- but {} parameter{} supplied",
2451
- expected_arg_count,
2452
- if expected_arg_count == 1 { "" } else { "s" } ,
2453
- supplied_arg_count,
2454
- if supplied_arg_count == 1 { " was" } else { "s were" } ) ;
2464
+ parameter_count_error ( tcx. sess , sp, fn_inputs, expected_arg_count,
2465
+ supplied_arg_count, "E0060" , true ) ;
2455
2466
expected_arg_tys = & [ ] ;
2456
2467
self . err_args ( supplied_arg_count)
2457
2468
}
2458
2469
} else {
2459
- span_err ! ( tcx. sess, sp, E0061 ,
2460
- "this function takes {} parameter{} but {} parameter{} supplied" ,
2461
- expected_arg_count,
2462
- if expected_arg_count == 1 { "" } else { "s" } ,
2463
- supplied_arg_count,
2464
- if supplied_arg_count == 1 { " was" } else { "s were" } ) ;
2470
+ parameter_count_error ( tcx. sess , sp, fn_inputs, expected_arg_count, supplied_arg_count,
2471
+ "E0061" , false ) ;
2465
2472
expected_arg_tys = & [ ] ;
2466
2473
self . err_args ( supplied_arg_count)
2467
2474
} ;
0 commit comments