@@ -5,7 +5,7 @@ use rustc_hir::hir_id::OwnerId;
5
5
use rustc_hir:: { Impl , ImplItem , ImplItemKind , ImplItemRef , ItemKind , Node , TraitRef } ;
6
6
use rustc_lint:: LateContext ;
7
7
use rustc_span:: Span ;
8
- use rustc_span:: symbol:: { Ident , Symbol , kw} ;
8
+ use rustc_span:: symbol:: { Ident , kw} ;
9
9
10
10
use super :: RENAMED_FUNCTION_PARAMS ;
11
11
@@ -51,22 +51,31 @@ struct RenamedFnArgs(Vec<(Span, String)>);
51
51
impl RenamedFnArgs {
52
52
/// Comparing between an iterator of default names and one with current names,
53
53
/// then collect the ones that got renamed.
54
- fn new < I , T > ( default_names : & mut I , current_names : & mut T ) -> Self
54
+ fn new < I1 , I2 > ( default_idents : & mut I1 , current_idents : & mut I2 ) -> Self
55
55
where
56
- I : Iterator < Item = Ident > ,
57
- T : Iterator < Item = Ident > ,
56
+ I1 : Iterator < Item = Option < Ident > > ,
57
+ I2 : Iterator < Item = Option < Ident > > ,
58
58
{
59
59
let mut renamed: Vec < ( Span , String ) > = vec ! [ ] ;
60
60
61
- debug_assert ! ( default_names. size_hint( ) == current_names. size_hint( ) ) ;
62
- while let ( Some ( def_name) , Some ( cur_name) ) = ( default_names. next ( ) , current_names. next ( ) ) {
63
- let current_name = cur_name. name ;
64
- let default_name = def_name. name ;
65
- if is_unused_or_empty_symbol ( current_name) || is_unused_or_empty_symbol ( default_name) {
66
- continue ;
67
- }
68
- if current_name != default_name {
69
- renamed. push ( ( cur_name. span , default_name. to_string ( ) ) ) ;
61
+ debug_assert ! ( default_idents. size_hint( ) == current_idents. size_hint( ) ) ;
62
+ while let ( Some ( default_ident) , Some ( current_ident) ) = ( default_idents. next ( ) , current_idents. next ( ) ) {
63
+ let has_name_to_check = |ident : Option < Ident > | {
64
+ if let Some ( ident) = ident
65
+ && ident. name != kw:: Underscore
66
+ && !ident. name . as_str ( ) . starts_with ( '_' )
67
+ {
68
+ Some ( ident)
69
+ } else {
70
+ None
71
+ }
72
+ } ;
73
+
74
+ if let Some ( default_ident) = has_name_to_check ( default_ident)
75
+ && let Some ( current_ident) = has_name_to_check ( current_ident)
76
+ && default_ident. name != current_ident. name
77
+ {
78
+ renamed. push ( ( current_ident. span , default_ident. to_string ( ) ) ) ;
70
79
}
71
80
}
72
81
@@ -83,14 +92,6 @@ impl RenamedFnArgs {
83
92
}
84
93
}
85
94
86
- fn is_unused_or_empty_symbol ( symbol : Symbol ) -> bool {
87
- // FIXME: `body_param_names` currently returning empty symbols for `wild` as well,
88
- // so we need to check if the symbol is empty first.
89
- // Therefore the check of whether it's equal to [`kw::Underscore`] has no use for now,
90
- // but it would be nice to keep it here just to be future-proof.
91
- symbol. is_empty ( ) || symbol == kw:: Underscore || symbol. as_str ( ) . starts_with ( '_' )
92
- }
93
-
94
95
/// Get the [`trait_item_def_id`](ImplItemRef::trait_item_def_id) of a relevant impl item.
95
96
fn trait_item_def_id_of_impl ( items : & [ ImplItemRef ] , target : OwnerId ) -> Option < DefId > {
96
97
items. iter ( ) . find_map ( |item| {
0 commit comments