]> 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 740dd2bcb3fcf225c336689ba57667ffffa5ef6b..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,9 +42,12 @@ 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::DerefRef { autoderefs, autoref, .. }) =
-                    cx.tables.adjustments.get(&e.id).map(|a| &a.kind) {
-                    if autoderefs > 1 && autoref.is_some() {
+                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,
@@ -59,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,