3
3
//! This lint is **warn** by default
4
4
5
5
use clippy_utils:: diagnostics:: span_lint_and_then;
6
- use clippy_utils:: is_automatically_derived;
7
6
use clippy_utils:: source:: snippet_opt;
8
7
use if_chain:: if_chain;
9
8
use 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 } ;
11
10
use rustc_lint:: { LateContext , LateLintPass } ;
12
11
use rustc_middle:: ty;
13
12
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment } ;
14
13
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
15
- use rustc_span:: def_id:: LocalDefId ;
16
14
17
15
declare_clippy_lint ! {
18
16
/// **What it does:** Checks for address of operations (`&`) that are going to
@@ -37,15 +35,13 @@ declare_clippy_lint! {
37
35
}
38
36
39
37
#[ derive( Default ) ]
40
- pub struct NeedlessBorrow {
41
- derived_item : Option < LocalDefId > ,
42
- }
38
+ pub struct NeedlessBorrow ;
43
39
44
40
impl_lint_pass ! ( NeedlessBorrow => [ NEEDLESS_BORROW ] ) ;
45
41
46
42
impl < ' tcx > LateLintPass < ' tcx > for NeedlessBorrow {
47
43
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 ( ) {
49
45
return ;
50
46
}
51
47
if let ExprKind :: AddrOf ( BorrowKind :: Ref , Mutability :: Not , inner) = e. kind {
@@ -86,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
86
82
}
87
83
}
88
84
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 ( ) {
90
86
return ;
91
87
}
92
88
if_chain ! {
@@ -116,20 +112,4 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
116
112
}
117
113
}
118
114
}
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
- }
135
115
}
0 commit comments