33//! This lint is **warn** by default
44
55use clippy_utils:: diagnostics:: span_lint_and_then;
6- use clippy_utils:: is_automatically_derived;
76use clippy_utils:: source:: snippet_opt;
87use if_chain:: if_chain;
98use rustc_errors:: Applicability ;
10- use rustc_hir:: { BindingAnnotation , BorrowKind , Expr , ExprKind , Item , Mutability , Pat , PatKind } ;
9+ use rustc_hir:: { BindingAnnotation , BorrowKind , Expr , ExprKind , Mutability , Pat , PatKind } ;
1110use rustc_lint:: { LateContext , LateLintPass } ;
1211use rustc_middle:: ty;
1312use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment } ;
1413use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
15- use rustc_span:: def_id:: LocalDefId ;
1614
1715declare_clippy_lint ! {
1816 /// **What it does:** Checks for address of operations (`&`) that are going to
@@ -37,15 +35,13 @@ declare_clippy_lint! {
3735}
3836
3937#[ derive( Default ) ]
40- pub struct NeedlessBorrow {
41- derived_item : Option < LocalDefId > ,
42- }
38+ pub struct NeedlessBorrow ;
4339
4440impl_lint_pass ! ( NeedlessBorrow => [ NEEDLESS_BORROW ] ) ;
4541
4642impl < ' tcx > LateLintPass < ' tcx > for NeedlessBorrow {
4743 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' _ > ) {
48- if e. span . from_expansion ( ) || self . derived_item . is_some ( ) {
44+ if e. span . from_expansion ( ) {
4945 return ;
5046 }
5147 if let ExprKind :: AddrOf ( BorrowKind :: Ref , Mutability :: Not , inner) = e. kind {
@@ -86,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
8682 }
8783 }
8884 fn check_pat ( & mut self , cx : & LateContext < ' tcx > , pat : & ' tcx Pat < ' _ > ) {
89- if pat. span . from_expansion ( ) || self . derived_item . is_some ( ) {
85+ if pat. span . from_expansion ( ) {
9086 return ;
9187 }
9288 if_chain ! {
@@ -116,20 +112,4 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
116112 }
117113 }
118114 }
119-
120- fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' _ > ) {
121- let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
122- if is_automatically_derived ( attrs) {
123- debug_assert ! ( self . derived_item. is_none( ) ) ;
124- self . derived_item = Some ( item. def_id ) ;
125- }
126- }
127-
128- fn check_item_post ( & mut self , _: & LateContext < ' tcx > , item : & ' tcx Item < ' _ > ) {
129- if let Some ( id) = self . derived_item {
130- if item. def_id == id {
131- self . derived_item = None ;
132- }
133- }
134- }
135115}
0 commit comments