@@ -2,7 +2,7 @@ use if_chain::if_chain;
22use rustc:: hir:: map:: Map ;
33use rustc_hir:: def:: Res ;
44use rustc_hir:: intravisit:: { walk_path, NestedVisitorMap , Visitor } ;
5- use rustc_hir:: { AssocItemKind , HirId , ImplItemKind , ImplItemRef , Item , ItemKind , Path } ;
5+ use rustc_hir:: { AssocItemKind , HirId , ImplItem , ImplItemKind , ImplItemRef , ItemKind , Path } ;
66use rustc_lint:: { LateContext , LateLintPass } ;
77use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
88
@@ -40,10 +40,12 @@ declare_clippy_lint! {
4040declare_lint_pass ! ( UnusedSelf => [ UNUSED_SELF ] ) ;
4141
4242impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for UnusedSelf {
43- fn check_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & Item < ' _ > ) {
44- if item . span . from_expansion ( ) {
43+ fn check_impl_item ( & mut self , cx : & LateContext < ' a , ' tcx > , impl_item : & ImplItem < ' _ > ) {
44+ if impl_item . span . from_expansion ( ) {
4545 return ;
4646 }
47+ let parent = cx. tcx . hir ( ) . get_parent_item ( impl_item. hir_id ) ;
48+ let item = cx. tcx . hir ( ) . expect_item ( parent) ;
4749 if let ItemKind :: Impl {
4850 of_trait : None ,
4951 items : impl_item_refs,
@@ -56,10 +58,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedSelf {
5658 kind: AssocItemKind :: Method { has_self: true } ,
5759 ..
5860 } = impl_item_ref;
59- let impl_item = cx. tcx. hir( ) . impl_item( impl_item_ref. id) ;
6061 if let ImplItemKind :: Method ( _, body_id) = & impl_item. kind;
62+ let body = cx. tcx. hir( ) . body( * body_id) ;
63+ if !body. params. is_empty( ) ;
6164 then {
62- let body = cx. tcx. hir( ) . body( * body_id) ;
6365 let self_param = & body. params[ 0 ] ;
6466 let self_hir_id = self_param. pat. hir_id;
6567 let mut visitor = UnusedSelfVisitor {
@@ -75,7 +77,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedSelf {
7577 self_param. span,
7678 "unused `self` argument" ,
7779 "consider refactoring to a associated function" ,
78- )
80+ ) ;
81+ return ;
7982 }
8083 }
8184 }
0 commit comments