]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/needless_borrow.rs
use BindingAnnotation instead of BindingMode
[rust.git] / clippy_lints / src / needless_borrow.rs
index 4f5ff86c5e8f4fa4f1ccf1012a20638046fdcefb..385fcc86adb6a50f8fce8fe28cb89946c8da4737 100644 (file)
@@ -3,8 +3,9 @@
 //! This lint is **warn** by default
 
 use rustc::lint::*;
-use rustc::hir::{ExprAddrOf, Expr, MutImmutable, Pat, PatKind, BindingMode};
+use rustc::hir::{ExprAddrOf, Expr, MutImmutable, Pat, PatKind, BindingAnnotation};
 use rustc::ty;
+use rustc::ty::adjustment::{Adjustment, Adjust};
 use utils::{span_lint, in_macro};
 
 /// **What it does:** Checks for address of operations (`&`) that are going to
@@ -41,13 +42,18 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
         }
         if let ExprAddrOf(MutImmutable, ref inner) = e.node {
             if let ty::TyRef(..) = cx.tables.expr_ty(inner).sty {
-                if let Some(&ty::adjustment::Adjust::Deref(Some(_))) =
-                    cx.tables.adjustments.get(&e.id).map(|a| &a.kind) {
-                    span_lint(cx,
-                              NEEDLESS_BORROW,
-                              e.span,
-                              "this expression borrows a reference that is immediately dereferenced by the \
-                               compiler");
+                for adj3 in cx.tables.expr_adjustments(e).windows(3) {
+                    if let [
+                        Adjustment { kind: Adjust::Deref(_), .. },
+                        Adjustment { kind: Adjust::Deref(_), .. },
+                        Adjustment { kind: Adjust::Borrow(_), .. }
+                    ] = *adj3 {
+                        span_lint(cx,
+                                  NEEDLESS_BORROW,
+                                  e.span,
+                                  "this expression borrows a reference that is immediately dereferenced by the \
+                                   compiler");
+                    }
                 }
             }
         }
@@ -57,7 +63,7 @@ fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
             return;
         }
         if_let_chain! {[
-            let PatKind::Binding(BindingMode::BindByRef(MutImmutable), _, _, _) = pat.node,
+            let PatKind::Binding(BindingAnnotation::Ref, _, _, _) = pat.node,
             let ty::TyRef(_, ref tam) = cx.tables.pat_ty(pat).sty,
             tam.mutbl == MutImmutable,
             let ty::TyRef(_, ref tam) = tam.ty.sty,