about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeremy Stucki <jeremy@myelin.ch>2019-08-11 21:02:01 +0200
committerJeremy Stucki <jeremy@myelin.ch>2019-08-11 21:02:01 +0200
commit5fd7d44f36ae530c4cb1ccfda08f028918e53ea6 (patch)
tree4784d0adfbabef86b01211ef4e7d51b3e4d98bcb
parentb651f19eb87db789f8fd24a7791add446d869630 (diff)
downloadrust-5fd7d44f36ae530c4cb1ccfda08f028918e53ea6.tar.gz
rust-5fd7d44f36ae530c4cb1ccfda08f028918e53ea6.zip
Refactor if_chain
Co-authored-by: Philipp Krones <hello@philkrones.com>
-rw-r--r--clippy_lints/src/methods/mod.rs49
1 files changed, 25 insertions, 24 deletions
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 0ab7785501a..dc5c579b7e5 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -2174,38 +2174,39 @@ fn lint_flat_map_identity<'a, 'tcx>(
         if match_trait_method(cx, expr, &paths::ITERATOR);
 
         if flat_map_args.len() == 2;
-        if let hir::ExprKind::Closure(_, _, body_id, _, _) = flat_map_args[1].node;
-        let body = cx.tcx.hir().body(body_id);
-
-        if body.arguments.len() == 1;
-        if let hir::PatKind::Binding(_, _, binding_ident, _) = body.arguments[0].pat.node;
-        if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = body.value.node;
-
-        if path.segments.len() == 1;
-        if path.segments[0].ident.as_str() == binding_ident.as_str();
 
         then {
-            let msg = "called `flat_map(|x| x)` on an `Iterator`. \
-                       This can be simplified by calling `flatten().`";
-            span_lint(cx, FLAT_MAP_IDENTITY, expr.span, msg);
-        }
-    }
+            if_chain! {
+                if let hir::ExprKind::Closure(_, _, body_id, _, _) = flat_map_args[1].node;
+                let body = cx.tcx.hir().body(body_id);
 
-    if_chain! {
-        if match_trait_method(cx, expr, &paths::ITERATOR);
+                if body.arguments.len() == 1;
+                if let hir::PatKind::Binding(_, _, binding_ident, _) = body.arguments[0].pat.node;
+                if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = body.value.node;
 
-        if flat_map_args.len() == 2;
+                if path.segments.len() == 1;
+                if path.segments[0].ident.as_str() == binding_ident.as_str();
 
-        let expr = &flat_map_args[1];
+                then {
+                    let msg = "called `flat_map(|x| x)` on an `Iterator`. \
+                               This can be simplified by calling `flatten().`";
+                    span_lint(cx, FLAT_MAP_IDENTITY, expr.span, msg);
+                }
+            }
 
-        if let hir::ExprKind::Path(ref qpath) = expr.node;
+            if_chain! {
+                let expr = &flat_map_args[1];
 
-        if match_qpath(qpath, &paths::STD_CONVERT_IDENTITY);
+                if let hir::ExprKind::Path(ref qpath) = expr.node;
 
-        then {
-            let msg = "called `flat_map(std::convert::identity)` on an `Iterator`. \
-                       This can be simplified by calling `flatten().`";
-            span_lint(cx, FLAT_MAP_IDENTITY, expr.span, msg);
+                if match_qpath(qpath, &paths::STD_CONVERT_IDENTITY);
+
+                then {
+                    let msg = "called `flat_map(std::convert::identity)` on an `Iterator`. \
+                               This can be simplified by calling `flatten().`";
+                    span_lint(cx, FLAT_MAP_IDENTITY, expr.span, msg);
+                }
+            }
         }
     }
 }