@@ -13,7 +13,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
13
13
use rustc_middle:: lint:: in_external_macro;
14
14
use rustc_middle:: ty;
15
15
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment } ;
16
- use rustc_session:: { declare_tool_lint , impl_lint_pass } ;
16
+ use rustc_session:: { declare_lint_pass , declare_tool_lint } ;
17
17
18
18
declare_clippy_lint ! {
19
19
/// **What it does:** Checks for address of operations (`&`) that are going to
@@ -37,8 +37,7 @@ declare_clippy_lint! {
37
37
"taking a reference that is going to be automatically dereferenced"
38
38
}
39
39
40
- pub struct NeedlessBorrow ;
41
- impl_lint_pass ! ( NeedlessBorrow => [ NEEDLESS_BORROW ] ) ;
40
+ declare_lint_pass ! ( NeedlessBorrow => [ NEEDLESS_BORROW ] ) ;
42
41
43
42
impl < ' tcx > LateLintPass < ' tcx > for NeedlessBorrow {
44
43
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' _ > ) {
@@ -108,12 +107,11 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
108
107
] ;
109
108
110
109
foreach_local_usage( cx, id, search_loc, |e| {
111
- if matches!(
110
+ // Check for auto-deref
111
+ if !matches!(
112
112
cx. typeck_results( ) . expr_adjustments( e) ,
113
113
[ Adjustment { kind: Adjust :: Deref ( _) , .. } , Adjustment { kind: Adjust :: Deref ( _) , .. } , ..]
114
114
) {
115
- // Compiler inserted deref, nothing to change here
116
- } else {
117
115
match get_parent_expr( cx, e) {
118
116
Some ( & Expr { span, kind: ExprKind :: Unary ( UnOp :: Deref , _) , .. } )
119
117
if span. ctxt( ) == ctxt => {
0 commit comments