@@ -2347,9 +2347,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2347
2347
2348
2348
let check_for_matched_generics = || {
2349
2349
if matched_inputs. iter ( ) . any ( |x| x. is_some ( ) )
2350
- && params_with_generics. iter ( ) . any ( |x| x. 0 . is_some ( ) )
2350
+ && params_with_generics. iter ( ) . any ( |x| x. 1 . is_some ( ) )
2351
2351
{
2352
- for ( idx, ( generic, _) ) in params_with_generics. iter ( ) . enumerate ( ) {
2352
+ for & ( idx, generic, _) in & params_with_generics {
2353
2353
// Param has to have a generic and be matched to be relevant
2354
2354
if matched_inputs[ idx. into ( ) ] . is_none ( ) {
2355
2355
continue ;
@@ -2362,7 +2362,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2362
2362
for unmatching_idx in idx + 1 ..params_with_generics. len ( ) {
2363
2363
if matched_inputs[ unmatching_idx. into ( ) ] . is_none ( )
2364
2364
&& let Some ( unmatched_idx_param_generic) =
2365
- params_with_generics[ unmatching_idx] . 0
2365
+ params_with_generics[ unmatching_idx] . 1
2366
2366
&& unmatched_idx_param_generic. name . ident ( )
2367
2367
== generic. name . ident ( )
2368
2368
{
@@ -2377,8 +2377,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2377
2377
2378
2378
let check_for_matched_generics = check_for_matched_generics ( ) ;
2379
2379
2380
- for ( idx, ( generic_param, param) ) in
2381
- params_with_generics. iter ( ) . enumerate ( ) . filter ( |( idx, _) | {
2380
+ for & ( idx, generic_param, param) in
2381
+ params_with_generics. iter ( ) . filter ( |& ( idx, _ , _) | {
2382
2382
check_for_matched_generics
2383
2383
|| expected_idx. is_none_or ( |expected_idx| expected_idx == * idx)
2384
2384
} )
@@ -2390,8 +2390,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2390
2390
2391
2391
let other_params_matched: Vec < ( usize , & hir:: Param < ' _ > ) > = params_with_generics
2392
2392
. iter ( )
2393
- . enumerate ( )
2394
- . filter ( |( other_idx, ( other_generic_param, _) ) | {
2393
+ . filter ( |( other_idx, other_generic_param, _) | {
2395
2394
if * other_idx == idx {
2396
2395
return false ;
2397
2396
}
@@ -2410,18 +2409,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2410
2409
}
2411
2410
other_generic_param. name . ident ( ) == generic_param. name . ident ( )
2412
2411
} )
2413
- . map ( |( other_idx, ( _, other_param) ) | ( other_idx, * other_param) )
2412
+ . map ( |& ( other_idx, _, other_param) | ( other_idx, other_param) )
2414
2413
. collect ( ) ;
2415
2414
2416
2415
if !other_params_matched. is_empty ( ) {
2417
2416
let other_param_matched_names: Vec < String > = other_params_matched
2418
2417
. iter ( )
2419
- . map ( |( _ , other_param) | {
2418
+ . map ( |( idx , other_param) | {
2420
2419
if let hir:: PatKind :: Binding ( _, _, ident, _) = other_param. pat . kind
2421
2420
{
2422
2421
format ! ( "`{ident}`" )
2423
2422
} else {
2424
- "{unknown}" . to_string ( )
2423
+ format ! ( "parameter #{}" , idx + 1 )
2425
2424
}
2426
2425
} )
2427
2426
. collect ( ) ;
@@ -2478,18 +2477,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2478
2477
{
2479
2478
let param_idents_matching: Vec < String > = params_with_generics
2480
2479
. iter ( )
2481
- . filter ( |( generic, _) | {
2480
+ . filter ( |( _ , generic, _) | {
2482
2481
if let Some ( generic) = generic {
2483
2482
generic. name . ident ( ) == generic_param. name . ident ( )
2484
2483
} else {
2485
2484
false
2486
2485
}
2487
2486
} )
2488
- . map ( |( _, param) | {
2487
+ . map ( |( idx , _, param) | {
2489
2488
if let hir:: PatKind :: Binding ( _, _, ident, _) = param. pat . kind {
2490
2489
format ! ( "`{ident}`" )
2491
2490
} else {
2492
- "{unknown}" . to_string ( )
2491
+ format ! ( "parameter #{}" , idx + 1 )
2493
2492
}
2494
2493
} )
2495
2494
. collect ( ) ;
@@ -2498,8 +2497,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2498
2497
spans. push_span_label (
2499
2498
generic_param. span ,
2500
2499
format ! (
2501
- "{} all reference this parameter {} " ,
2500
+ "{} {} reference this parameter `{}` " ,
2502
2501
display_list_with_comma_and( & param_idents_matching) ,
2502
+ if param_idents_matching. len( ) == 2 { "both" } else { "all" } ,
2503
2503
generic_param. name. ident( ) . name,
2504
2504
) ,
2505
2505
) ;
@@ -2580,7 +2580,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2580
2580
2581
2581
if let Some ( params_with_generics) = self . get_hir_params_with_generics ( def_id, is_method) {
2582
2582
debug_assert_eq ! ( params_with_generics. len( ) , matched_inputs. len( ) ) ;
2583
- for ( idx, ( generic_param, _) ) in params_with_generics. iter ( ) . enumerate ( ) {
2583
+ for & ( idx, generic_param, _) in & params_with_generics {
2584
2584
if matched_inputs[ idx. into ( ) ] . is_none ( ) {
2585
2585
continue ;
2586
2586
}
@@ -2594,20 +2594,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2594
2594
} ;
2595
2595
2596
2596
let mut idxs_matched: Vec < usize > = vec ! [ ] ;
2597
- for ( other_idx, ( _, _) ) in params_with_generics . iter ( ) . enumerate ( ) . filter (
2598
- | ( other_idx, ( other_generic_param, _) ) | {
2599
- if * other_idx == idx {
2597
+ for & ( other_idx, _, _) in
2598
+ params_with_generics . iter ( ) . filter ( | & & ( other_idx, other_generic_param, _) | {
2599
+ if other_idx == idx {
2600
2600
return false ;
2601
2601
}
2602
2602
let Some ( other_generic_param) = other_generic_param else {
2603
2603
return false ;
2604
2604
} ;
2605
- if matched_inputs[ ( * other_idx) . into ( ) ] . is_some ( ) {
2605
+ if matched_inputs[ other_idx. into ( ) ] . is_some ( ) {
2606
2606
return false ;
2607
2607
}
2608
2608
other_generic_param. name . ident ( ) == generic_param. name . ident ( )
2609
- } ,
2610
- ) {
2609
+ } )
2610
+ {
2611
2611
idxs_matched. push ( other_idx) ;
2612
2612
}
2613
2613
@@ -2642,7 +2642,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2642
2642
& self ,
2643
2643
def_id : DefId ,
2644
2644
is_method : bool ,
2645
- ) -> Option < Vec < ( Option < & hir:: GenericParam < ' _ > > , & hir:: Param < ' _ > ) > > {
2645
+ ) -> Option < Vec < ( usize , Option < & hir:: GenericParam < ' _ > > , & hir:: Param < ' _ > ) > > {
2646
2646
let fn_node = self . tcx . hir ( ) . get_if_local ( def_id) ?;
2647
2647
let fn_decl = fn_node. fn_decl ( ) ?;
2648
2648
@@ -2685,7 +2685,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2685
2685
}
2686
2686
2687
2687
debug_assert_eq ! ( params. len( ) , generic_params. len( ) ) ;
2688
- Some ( generic_params. into_iter ( ) . zip ( params) . collect ( ) )
2688
+ Some (
2689
+ generic_params
2690
+ . into_iter ( )
2691
+ . zip ( params)
2692
+ . enumerate ( )
2693
+ . map ( |( a, ( b, c) ) | ( a, b, c) )
2694
+ . collect ( ) ,
2695
+ )
2689
2696
}
2690
2697
}
2691
2698
0 commit comments