about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTakayuki Nakata <f.seasons017@gmail.com>2020-09-08 08:34:51 +0900
committerTakayuki Nakata <f.seasons017@gmail.com>2020-09-08 08:34:51 +0900
commit5d085ad011a602e004e7d33fa0b9074c7dab36fc (patch)
treee4f034fc38ba8c4900919798bb514947f4e2aecf
parent619ca76731e7209288fd3ebf1ae243c050486c12 (diff)
downloadrust-5d085ad011a602e004e7d33fa0b9074c7dab36fc.tar.gz
rust-5d085ad011a602e004e7d33fa0b9074c7dab36fc.zip
Some refactoring
-rw-r--r--clippy_lints/src/loops.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs
index c27acdd2236..c59185bd7bd 100644
--- a/clippy_lints/src/loops.rs
+++ b/clippy_lints/src/loops.rs
@@ -1131,6 +1131,10 @@ fn detect_same_item_push<'tcx>(
     body: &'tcx Expr<'_>,
     _: &'tcx Expr<'_>,
 ) {
+    if !matches!(pat.kind, PatKind::Wild) {
+        return;
+    }
+
     // Determine whether it is safe to lint the body
     let mut same_item_push_visitor = SameItemPushVisitor {
         should_lint: true,
@@ -1149,8 +1153,8 @@ fn detect_same_item_push<'tcx>(
                 .map_or(false, |id| implements_trait(cx, ty, id, &[]))
             {
                 // Make sure that the push does not involve possibly mutating values
-                if let PatKind::Wild = pat.kind {
-                    if let ExprKind::Path(ref qpath) = pushed_item.kind {
+                match pushed_item.kind {
+                    ExprKind::Path(ref qpath) => {
                         match qpath_res(cx, qpath, pushed_item.hir_id) {
                             // immutable bindings that are initialized with literal or constant
                             Res::Local(hir_id) => {
@@ -1161,7 +1165,7 @@ fn detect_same_item_push<'tcx>(
                                     if !matches!(bind_ann, BindingAnnotation::RefMut | BindingAnnotation::Mutable);
                                     let parent_node = cx.tcx.hir().get_parent_node(hir_id);
                                     if let Some(Node::Local(parent_let_expr)) = cx.tcx.hir().find(parent_node);
-                                    if let rustc_hir::Local { init: Some(init), .. } = parent_let_expr;
+                                    if let Some(init) = parent_let_expr.init;
                                     then {
                                         match init.kind {
                                             // immutable bindings that are initialized with literal
@@ -1181,10 +1185,9 @@ fn detect_same_item_push<'tcx>(
                             Res::Def(DefKind::Const, ..) => emit_lint(cx, vec, pushed_item),
                             _ => {},
                         }
-                    } else if let ExprKind::Lit(..) = pushed_item.kind {
-                        // literal
-                        emit_lint(cx, vec, pushed_item);
-                    }
+                    },
+                    ExprKind::Lit(..) => emit_lint(cx, vec, pushed_item),
+                    _ => {},
                 }
             }
         }