]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/clippy/clippy_lints/src/shadow.rs
Merge commit '98e2b9f25b6db4b2680a3d388456d9f95cb28344' into clippyup
[rust.git] / src / tools / clippy / clippy_lints / src / shadow.rs
index 612d2fd84cb6fd70029f83556a2c007edcb849bd..d6101bd5e36a2d53744cc224acf5436e82add96c 100644 (file)
@@ -130,12 +130,12 @@ fn check_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'_>, bindings: &
     let len = bindings.len();
     for stmt in block.stmts {
         match stmt.kind {
-            StmtKind::Local(ref local) => check_local(cx, local, bindings),
-            StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => check_expr(cx, e, bindings),
+            StmtKind::Local(local) => check_local(cx, local, bindings),
+            StmtKind::Expr(e) | StmtKind::Semi(e) => check_expr(cx, e, bindings),
             StmtKind::Item(..) => {},
         }
     }
-    if let Some(ref o) = block.expr {
+    if let Some(o) = block.expr {
         check_expr(cx, o, bindings);
     }
     bindings.truncate(len);
@@ -149,16 +149,16 @@ fn check_local<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>, bindings: &
         return;
     }
     let Local {
-        ref pat,
+        pat,
         ref ty,
         ref init,
         span,
         ..
     } = *local;
-    if let Some(ref t) = *ty {
+    if let Some(t) = *ty {
         check_ty(cx, t, bindings)
     }
-    if let Some(ref o) = *init {
+    if let Some(o) = *init {
         check_expr(cx, o, bindings);
         check_pat(cx, pat, Some(o), span, bindings);
     } else {
@@ -196,34 +196,34 @@ fn check_pat<'tcx>(
                     bindings.push((name, ident.span));
                 }
             }
-            if let Some(ref p) = *inner {
+            if let Some(p) = *inner {
                 check_pat(cx, p, init, span, bindings);
             }
         },
         PatKind::Struct(_, pfields, _) => {
             if let Some(init_struct) = init {
-                if let ExprKind::Struct(_, ref efields, _) = init_struct.kind {
+                if let ExprKind::Struct(_, efields, _) = init_struct.kind {
                     for field in pfields {
                         let name = field.ident.name;
                         let efield = efields
                             .iter()
                             .find_map(|f| if f.ident.name == name { Some(&*f.expr) } else { None });
-                        check_pat(cx, &field.pat, efield, span, bindings);
+                        check_pat(cx, field.pat, efield, span, bindings);
                     }
                 } else {
                     for field in pfields {
-                        check_pat(cx, &field.pat, init, span, bindings);
+                        check_pat(cx, field.pat, init, span, bindings);
                     }
                 }
             } else {
                 for field in pfields {
-                    check_pat(cx, &field.pat, None, span, bindings);
+                    check_pat(cx, field.pat, None, span, bindings);
                 }
             }
         },
         PatKind::Tuple(inner, _) => {
             if let Some(init_tup) = init {
-                if let ExprKind::Tup(ref tup) = init_tup.kind {
+                if let ExprKind::Tup(tup) = init_tup.kind {
                     for (i, p) in inner.iter().enumerate() {
                         check_pat(cx, p, Some(&tup[i]), p.span, bindings);
                     }
@@ -238,10 +238,10 @@ fn check_pat<'tcx>(
                 }
             }
         },
-        PatKind::Box(ref inner) => {
+        PatKind::Box(inner) => {
             if let Some(initp) = init {
-                if let ExprKind::Box(ref inner_init) = initp.kind {
-                    check_pat(cx, inner, Some(&**inner_init), span, bindings);
+                if let ExprKind::Box(inner_init) = initp.kind {
+                    check_pat(cx, inner, Some(inner_init), span, bindings);
                 } else {
                     check_pat(cx, inner, init, span, bindings);
                 }
@@ -249,7 +249,7 @@ fn check_pat<'tcx>(
                 check_pat(cx, inner, init, span, bindings);
             }
         },
-        PatKind::Ref(ref inner, _) => check_pat(cx, inner, init, span, bindings),
+        PatKind::Ref(inner, _) => check_pat(cx, inner, init, span, bindings),
         // PatVec(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
         _ => (),
     }
@@ -323,11 +323,10 @@ fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut
         return;
     }
     match expr.kind {
-        ExprKind::Unary(_, ref e)
-        | ExprKind::Field(ref e, _)
-        | ExprKind::AddrOf(_, _, ref e)
-        | ExprKind::Box(ref e) => check_expr(cx, e, bindings),
-        ExprKind::Block(ref block, _) | ExprKind::Loop(ref block, ..) => check_block(cx, block, bindings),
+        ExprKind::Unary(_, e) | ExprKind::Field(e, _) | ExprKind::AddrOf(_, _, e) | ExprKind::Box(e) => {
+            check_expr(cx, e, bindings)
+        },
+        ExprKind::Block(block, _) | ExprKind::Loop(block, ..) => check_block(cx, block, bindings),
         // ExprKind::Call
         // ExprKind::MethodCall
         ExprKind::Array(v) | ExprKind::Tup(v) => {
@@ -335,18 +334,18 @@ fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut
                 check_expr(cx, e, bindings)
             }
         },
-        ExprKind::If(ref cond, ref then, ref otherwise) => {
+        ExprKind::If(cond, then, ref otherwise) => {
             check_expr(cx, cond, bindings);
-            check_expr(cx, &**then, bindings);
-            if let Some(ref o) = *otherwise {
+            check_expr(cx, then, bindings);
+            if let Some(o) = *otherwise {
                 check_expr(cx, o, bindings);
             }
         },
-        ExprKind::Match(ref init, arms, _) => {
+        ExprKind::Match(init, arms, _) => {
             check_expr(cx, init, bindings);
             let len = bindings.len();
             for arm in arms {
-                check_pat(cx, &arm.pat, Some(&**init), arm.pat.span, bindings);
+                check_pat(cx, arm.pat, Some(init), arm.pat.span, bindings);
                 // This is ugly, but needed to get the right type
                 if let Some(ref guard) = arm.guard {
                     match guard {
@@ -357,7 +356,7 @@ fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut
                         },
                     }
                 }
-                check_expr(cx, &arm.body, bindings);
+                check_expr(cx, arm.body, bindings);
                 bindings.truncate(len);
             }
         },
@@ -367,14 +366,12 @@ fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut
 
 fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: &'tcx Ty<'_>, bindings: &mut Vec<(Symbol, Span)>) {
     match ty.kind {
-        TyKind::Slice(ref sty) => check_ty(cx, sty, bindings),
-        TyKind::Array(ref fty, ref anon_const) => {
+        TyKind::Slice(sty) => check_ty(cx, sty, bindings),
+        TyKind::Array(fty, ref anon_const) => {
             check_ty(cx, fty, bindings);
             check_expr(cx, &cx.tcx.hir().body(anon_const.body).value, bindings);
         },
-        TyKind::Ptr(MutTy { ty: ref mty, .. }) | TyKind::Rptr(_, MutTy { ty: ref mty, .. }) => {
-            check_ty(cx, mty, bindings)
-        },
+        TyKind::Ptr(MutTy { ty: mty, .. }) | TyKind::Rptr(_, MutTy { ty: mty, .. }) => check_ty(cx, mty, bindings),
         TyKind::Tup(tup) => {
             for t in tup {
                 check_ty(cx, t, bindings)
@@ -387,12 +384,12 @@ fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: &'tcx Ty<'_>, bindings: &mut Vec<(
 
 fn is_self_shadow(name: Symbol, expr: &Expr<'_>) -> bool {
     match expr.kind {
-        ExprKind::Box(ref inner) | ExprKind::AddrOf(_, _, ref inner) => is_self_shadow(name, inner),
-        ExprKind::Block(ref block, _) => {
+        ExprKind::Box(inner) | ExprKind::AddrOf(_, _, inner) => is_self_shadow(name, inner),
+        ExprKind::Block(block, _) => {
             block.stmts.is_empty() && block.expr.as_ref().map_or(false, |e| is_self_shadow(name, e))
         },
-        ExprKind::Unary(op, ref inner) => (UnOp::Deref == op) && is_self_shadow(name, inner),
-        ExprKind::Path(QPath::Resolved(_, ref path)) => path_eq_name(name, path),
+        ExprKind::Unary(op, inner) => (UnOp::Deref == op) && is_self_shadow(name, inner),
+        ExprKind::Path(QPath::Resolved(_, path)) => path_eq_name(name, path),
         _ => false,
     }
 }