Skip to content

Commit acd8b0d

Browse files
committed
of_trait first
1 parent 72817c4 commit acd8b0d

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

clippy_lints/src/same_name_method.rs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,12 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
6565
}) = &item.kind
6666
{
6767
if let TyKind::Path(QPath::Resolved(_, Path { res, .. })) = self_ty.kind {
68-
for impl_item_ref in (*items)
69-
.iter()
70-
.filter(|impl_item_ref| matches!(impl_item_ref.kind, rustc_hir::AssocItemKind::Fn { .. }))
71-
{
72-
let method_name = impl_item_ref.ident.as_str();
73-
match of_trait {
74-
Some(_trait_ref) => {
75-
// FIXME: try to collect default methods in trait.
76-
// but `rustc_middle::ty::assoc::AssocItems::items` is not public
77-
// if let Some(node)=cx.tcx.hir().find(trait_ref.hir_ref_id){
78-
// if let Node::TraitRef(TraitRef{path,..})=node{
79-
// if let Res::Def(DefKind::Trait,did)=path.res{
80-
// items is private
81-
// cx.tcx.associated_items(did).items.iter().filter(|_k,v|matches!(v,AssocKind::
82-
// Fn)). map(|(k,_v)|k).collect(); }
83-
// }
84-
// }
85-
68+
match of_trait {
69+
Some(_trait_ref) => {
70+
for impl_item_ref in (*items).iter().filter(|impl_item_ref| {
71+
matches!(impl_item_ref.kind, rustc_hir::AssocItemKind::Fn { .. })
72+
}) {
73+
let method_name = impl_item_ref.ident.as_str();
8674
let trait_span = impl_item_ref.span;
8775
if let Some(s) = mp.get_mut(res) {
8876
if let Some(impl_span) = s.impl_methods.get(&method_name) {
@@ -110,8 +98,13 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
11098
},
11199
);
112100
}
113-
},
114-
None => {
101+
}
102+
},
103+
None => {
104+
for impl_item_ref in (*items).iter().filter(|impl_item_ref| {
105+
matches!(impl_item_ref.kind, rustc_hir::AssocItemKind::Fn { .. })
106+
}) {
107+
let method_name = impl_item_ref.ident.as_str();
115108
let impl_span = impl_item_ref.span;
116109
if let Some(s) = mp.get_mut(res) {
117110
if let Some(trait_spans) = s.trait_methods.get(&method_name) {
@@ -136,8 +129,8 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
136129
},
137130
);
138131
}
139-
},
140-
}
132+
}
133+
},
141134
}
142135
}
143136
}

0 commit comments

Comments
 (0)