@@ -2347,9 +2347,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23472347
23482348 let check_for_matched_generics = || {
23492349 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 ( ) )
23512351 {
2352- for ( idx, ( generic, _) ) in params_with_generics. iter ( ) . enumerate ( ) {
2352+ for & ( idx, generic, _) in & params_with_generics {
23532353 // Param has to have a generic and be matched to be relevant
23542354 if matched_inputs[ idx. into ( ) ] . is_none ( ) {
23552355 continue ;
@@ -2362,7 +2362,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23622362 for unmatching_idx in idx + 1 ..params_with_generics. len ( ) {
23632363 if matched_inputs[ unmatching_idx. into ( ) ] . is_none ( )
23642364 && let Some ( unmatched_idx_param_generic) =
2365- params_with_generics[ unmatching_idx] . 0
2365+ params_with_generics[ unmatching_idx] . 1
23662366 && unmatched_idx_param_generic. name . ident ( )
23672367 == generic. name . ident ( )
23682368 {
@@ -2377,8 +2377,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23772377
23782378 let check_for_matched_generics = check_for_matched_generics ( ) ;
23792379
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, _ , _) | {
23822382 check_for_matched_generics
23832383 || expected_idx. is_none_or ( |expected_idx| expected_idx == * idx)
23842384 } )
@@ -2390,8 +2390,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23902390
23912391 let other_params_matched: Vec < ( usize , & hir:: Param < ' _ > ) > = params_with_generics
23922392 . iter ( )
2393- . enumerate ( )
2394- . filter ( |( other_idx, ( other_generic_param, _) ) | {
2393+ . filter ( |( other_idx, other_generic_param, _) | {
23952394 if * other_idx == idx {
23962395 return false ;
23972396 }
@@ -2410,18 +2409,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24102409 }
24112410 other_generic_param. name . ident ( ) == generic_param. name . ident ( )
24122411 } )
2413- . map ( |( other_idx, ( _, other_param) ) | ( other_idx, * other_param) )
2412+ . map ( |& ( other_idx, _, other_param) | ( other_idx, other_param) )
24142413 . collect ( ) ;
24152414
24162415 if !other_params_matched. is_empty ( ) {
24172416 let other_param_matched_names: Vec < String > = other_params_matched
24182417 . iter ( )
2419- . map ( |( _ , other_param) | {
2418+ . map ( |( idx , other_param) | {
24202419 if let hir:: PatKind :: Binding ( _, _, ident, _) = other_param. pat . kind
24212420 {
24222421 format ! ( "`{ident}`" )
24232422 } else {
2424- "{unknown}" . to_string ( )
2423+ format ! ( "parameter #{}" , idx + 1 )
24252424 }
24262425 } )
24272426 . collect ( ) ;
@@ -2478,18 +2477,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24782477 {
24792478 let param_idents_matching: Vec < String > = params_with_generics
24802479 . iter ( )
2481- . filter ( |( generic, _) | {
2480+ . filter ( |( _ , generic, _) | {
24822481 if let Some ( generic) = generic {
24832482 generic. name . ident ( ) == generic_param. name . ident ( )
24842483 } else {
24852484 false
24862485 }
24872486 } )
2488- . map ( |( _, param) | {
2487+ . map ( |( idx , _, param) | {
24892488 if let hir:: PatKind :: Binding ( _, _, ident, _) = param. pat . kind {
24902489 format ! ( "`{ident}`" )
24912490 } else {
2492- "{unknown}" . to_string ( )
2491+ format ! ( "parameter #{}" , idx + 1 )
24932492 }
24942493 } )
24952494 . collect ( ) ;
@@ -2498,8 +2497,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24982497 spans. push_span_label (
24992498 generic_param. span ,
25002499 format ! (
2501- "{} all reference this parameter {} " ,
2500+ "{} {} reference this parameter `{}` " ,
25022501 display_list_with_comma_and( & param_idents_matching) ,
2502+ if param_idents_matching. len( ) == 2 { "both" } else { "all" } ,
25032503 generic_param. name. ident( ) . name,
25042504 ) ,
25052505 ) ;
@@ -2580,7 +2580,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25802580
25812581 if let Some ( params_with_generics) = self . get_hir_params_with_generics ( def_id, is_method) {
25822582 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 {
25842584 if matched_inputs[ idx. into ( ) ] . is_none ( ) {
25852585 continue ;
25862586 }
@@ -2594,20 +2594,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25942594 } ;
25952595
25962596 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 {
26002600 return false ;
26012601 }
26022602 let Some ( other_generic_param) = other_generic_param else {
26032603 return false ;
26042604 } ;
2605- if matched_inputs[ ( * other_idx) . into ( ) ] . is_some ( ) {
2605+ if matched_inputs[ other_idx. into ( ) ] . is_some ( ) {
26062606 return false ;
26072607 }
26082608 other_generic_param. name . ident ( ) == generic_param. name . ident ( )
2609- } ,
2610- ) {
2609+ } )
2610+ {
26112611 idxs_matched. push ( other_idx) ;
26122612 }
26132613
@@ -2642,7 +2642,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26422642 & self ,
26432643 def_id : DefId ,
26442644 is_method : bool ,
2645- ) -> Option < Vec < ( Option < & hir:: GenericParam < ' _ > > , & hir:: Param < ' _ > ) > > {
2645+ ) -> Option < Vec < ( usize , Option < & hir:: GenericParam < ' _ > > , & hir:: Param < ' _ > ) > > {
26462646 let fn_node = self . tcx . hir ( ) . get_if_local ( def_id) ?;
26472647 let fn_decl = fn_node. fn_decl ( ) ?;
26482648
@@ -2685,7 +2685,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26852685 }
26862686
26872687 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+ )
26892696 }
26902697}
26912698
0 commit comments