@@ -19,7 +19,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
1919use  rustc_middle:: ty:: { self ,  IsSuggestable ,  Ty ,  TyCtxt } ; 
2020use  rustc_middle:: { bug,  span_bug} ; 
2121use  rustc_session:: Session ; 
22- use  rustc_span:: { DUMMY_SP ,  Ident ,  Span ,  Symbol ,   kw,  sym} ; 
22+ use  rustc_span:: { DUMMY_SP ,  Ident ,  Span ,  kw,  sym} ; 
2323use  rustc_trait_selection:: error_reporting:: infer:: { FailureCode ,  ObligationCauseExt } ; 
2424use  rustc_trait_selection:: infer:: InferCtxtExt ; 
2525use  rustc_trait_selection:: traits:: { self ,  ObligationCauseCode ,  ObligationCtxt ,  SelectionContext } ; 
@@ -2679,7 +2679,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26792679                    params. get ( is_method as  usize ..params. len ( )  - sig. decl . c_variadic  as  usize ) ?; 
26802680                debug_assert_eq ! ( params. len( ) ,  fn_inputs. len( ) ) ; 
26812681                Some ( ( 
2682-                     fn_inputs. zip ( params. iter ( ) . map ( |param| FnParam :: Name ( param) ) ) . collect ( ) , 
2682+                     fn_inputs. zip ( params. iter ( ) . map ( |& param| FnParam :: Name ( param) ) ) . collect ( ) , 
26832683                    generics, 
26842684                ) ) 
26852685            } 
@@ -2710,32 +2710,38 @@ impl<'tcx> Visitor<'tcx> for FindClosureArg<'tcx> {
27102710#[ derive( Clone ,  Copy ) ]  
27112711enum  FnParam < ' hir >  { 
27122712    Param ( & ' hir  hir:: Param < ' hir > ) , 
2713-     Name ( & ' hir   Ident ) , 
2713+     Name ( Ident ) , 
27142714} 
2715+ 
27152716impl  FnParam < ' _ >  { 
27162717    fn  span ( & self )  -> Span  { 
27172718        match  self  { 
2718-             Self :: Param ( x)  => x. span , 
2719-             Self :: Name ( x)  => x. span , 
2720-         } 
2721-     } 
2722- 
2723-     fn  name ( & self )  -> Option < Symbol >  { 
2724-         match  self  { 
2725-             Self :: Param ( x)  if  let  hir:: PatKind :: Binding ( _,  _,  ident,  _)  = x. pat . kind  => { 
2726-                 Some ( ident. name ) 
2727-             } 
2728-             Self :: Name ( x)  if  x. name  != kw:: Empty  => Some ( x. name ) , 
2729-             _ => None , 
2719+             Self :: Param ( param)  => param. span , 
2720+             Self :: Name ( ident)  => ident. span , 
27302721        } 
27312722    } 
27322723
27332724    fn  display ( & self ,  idx :  usize )  -> impl  ' _  + fmt:: Display  { 
27342725        struct  D < ' a > ( FnParam < ' a > ,  usize ) ; 
27352726        impl  fmt:: Display  for  D < ' _ >  { 
27362727            fn  fmt ( & self ,  f :  & mut  fmt:: Formatter < ' _ > )  -> fmt:: Result  { 
2737-                 if  let  Some ( name)  = self . 0 . name ( )  { 
2738-                     write ! ( f,  "`{name}`" ) 
2728+                 // A "unique" param name is one that (a) exists, and (b) is guaranteed to be unique 
2729+                 // among the parameters, i.e. `_` does not count. 
2730+                 let  unique_name = match  self . 0  { 
2731+                     FnParam :: Param ( param) 
2732+                         if  let  hir:: PatKind :: Binding ( _,  _,  ident,  _)  = param. pat . kind  =>
2733+                     { 
2734+                         Some ( ident. name ) 
2735+                     } 
2736+                     FnParam :: Name ( ident) 
2737+                         if  ident. name  != kw:: Empty  && ident. name  != kw:: Underscore  =>
2738+                     { 
2739+                         Some ( ident. name ) 
2740+                     } 
2741+                     _ => None , 
2742+                 } ; 
2743+                 if  let  Some ( unique_name)  = unique_name { 
2744+                     write ! ( f,  "`{unique_name}`" ) 
27392745                }  else  { 
27402746                    write ! ( f,  "parameter #{}" ,  self . 1  + 1 ) 
27412747                } 
0 commit comments