@@ -19,7 +19,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
19
19
use rustc_middle:: ty:: { self , IsSuggestable , Ty , TyCtxt } ;
20
20
use rustc_middle:: { bug, span_bug} ;
21
21
use rustc_session:: Session ;
22
- use rustc_span:: { DUMMY_SP , Ident , Span , Symbol , kw, sym} ;
22
+ use rustc_span:: { DUMMY_SP , Ident , Span , kw, sym} ;
23
23
use rustc_trait_selection:: error_reporting:: infer:: { FailureCode , ObligationCauseExt } ;
24
24
use rustc_trait_selection:: infer:: InferCtxtExt ;
25
25
use rustc_trait_selection:: traits:: { self , ObligationCauseCode , ObligationCtxt , SelectionContext } ;
@@ -2679,7 +2679,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2679
2679
params. get ( is_method as usize ..params. len ( ) - sig. decl . c_variadic as usize ) ?;
2680
2680
debug_assert_eq ! ( params. len( ) , fn_inputs. len( ) ) ;
2681
2681
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 ( ) ,
2683
2683
generics,
2684
2684
) )
2685
2685
}
@@ -2710,32 +2710,38 @@ impl<'tcx> Visitor<'tcx> for FindClosureArg<'tcx> {
2710
2710
#[ derive( Clone , Copy ) ]
2711
2711
enum FnParam < ' hir > {
2712
2712
Param ( & ' hir hir:: Param < ' hir > ) ,
2713
- Name ( & ' hir Ident ) ,
2713
+ Name ( Ident ) ,
2714
2714
}
2715
+
2715
2716
impl FnParam < ' _ > {
2716
2717
fn span ( & self ) -> Span {
2717
2718
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 ,
2730
2721
}
2731
2722
}
2732
2723
2733
2724
fn display ( & self , idx : usize ) -> impl ' _ + fmt:: Display {
2734
2725
struct D < ' a > ( FnParam < ' a > , usize ) ;
2735
2726
impl fmt:: Display for D < ' _ > {
2736
2727
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}`" )
2739
2745
} else {
2740
2746
write ! ( f, "parameter #{}" , self . 1 + 1 )
2741
2747
}
0 commit comments