@@ -92,7 +92,11 @@ fn check_trait_items(cx: &LateContext, item: &Item, trait_items: &[TraitItem]) {
92
92
fn is_named_self ( item : & TraitItem , name : & str ) -> bool {
93
93
item. name . as_str ( ) == name &&
94
94
if let MethodTraitItem ( ref sig, _) = item. node {
95
- is_self_sig ( sig)
95
+ if sig. decl . has_self ( ) {
96
+ sig. decl . inputs . len ( ) == 1
97
+ } else {
98
+ false
99
+ }
96
100
} else {
97
101
false
98
102
}
@@ -111,18 +115,22 @@ fn check_trait_items(cx: &LateContext, item: &Item, trait_items: &[TraitItem]) {
111
115
}
112
116
}
113
117
114
- fn check_impl_items ( cx : & LateContext , item : & Item , impl_items : & [ ImplItem ] ) {
115
- fn is_named_self ( item : & ImplItem , name : & str ) -> bool {
118
+ fn check_impl_items ( cx : & LateContext , item : & Item , impl_items : & [ ImplItemRef ] ) {
119
+ fn is_named_self ( cx : & LateContext , item : & ImplItemRef , name : & str ) -> bool {
116
120
item. name . as_str ( ) == name &&
117
- if let ImplItemKind :: Method ( ref sig, _) = item. node {
118
- is_self_sig ( sig)
121
+ if let AssociatedItemKind :: Method { has_self } = item. kind {
122
+ has_self && {
123
+ let did = cx. tcx . map . local_def_id ( item. id . node_id ) ;
124
+ let impl_ty = cx. tcx . item_type ( did) ;
125
+ impl_ty. fn_args ( ) . skip_binder ( ) . len ( ) == 1
126
+ }
119
127
} else {
120
128
false
121
129
}
122
130
}
123
131
124
- let is_empty = if let Some ( is_empty) = impl_items. iter ( ) . find ( |i| is_named_self ( i, "is_empty" ) ) {
125
- if cx. access_levels . is_exported ( is_empty. id ) {
132
+ let is_empty = if let Some ( is_empty) = impl_items. iter ( ) . find ( |i| is_named_self ( cx , i, "is_empty" ) ) {
133
+ if cx. access_levels . is_exported ( is_empty. id . node_id ) {
126
134
return ;
127
135
} else {
128
136
"a private"
@@ -131,8 +139,8 @@ fn check_impl_items(cx: &LateContext, item: &Item, impl_items: &[ImplItem]) {
131
139
"no corresponding"
132
140
} ;
133
141
134
- if let Some ( i) = impl_items. iter ( ) . find ( |i| is_named_self ( i, "len" ) ) {
135
- if cx. access_levels . is_exported ( i. id ) {
142
+ if let Some ( i) = impl_items. iter ( ) . find ( |i| is_named_self ( cx , i, "len" ) ) {
143
+ if cx. access_levels . is_exported ( i. id . node_id ) {
136
144
let def_id = cx. tcx . map . local_def_id ( item. id ) ;
137
145
let ty = cx. tcx . item_type ( def_id) ;
138
146
@@ -146,14 +154,6 @@ fn check_impl_items(cx: &LateContext, item: &Item, impl_items: &[ImplItem]) {
146
154
}
147
155
}
148
156
149
- fn is_self_sig ( sig : & MethodSig ) -> bool {
150
- if sig. decl . has_self ( ) {
151
- sig. decl . inputs . len ( ) == 1
152
- } else {
153
- false
154
- }
155
- }
156
-
157
157
fn check_cmp ( cx : & LateContext , span : Span , left : & Expr , right : & Expr , op : & str ) {
158
158
// check if we are in an is_empty() method
159
159
if let Some ( name) = get_item_name ( cx, left) {
0 commit comments