about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/eval_order_dependence.rs2
-rw-r--r--clippy_lints/src/misc_early.rs115
-rw-r--r--clippy_lints/src/no_effect.rs2
-rw-r--r--clippy_lints/src/utils/sugg.rs2
4 files changed, 63 insertions, 58 deletions
diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs
index b915d50671b..efd4e1e0334 100644
--- a/clippy_lints/src/eval_order_dependence.rs
+++ b/clippy_lints/src/eval_order_dependence.rs
@@ -101,7 +101,7 @@ struct DivergenceVisitor<'a, 'tcx> {
 impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
     fn maybe_walk_expr(&mut self, e: &'tcx Expr) {
         match e.node {
-            ExprKind::Closure(.., _) => {},
+            ExprKind::Closure(..) => {},
             ExprKind::Match(ref e, ref arms, _) => {
                 self.visit_expr(e);
                 for arm in arms {
diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs
index 2e1be755d09..17c44d148b4 100644
--- a/clippy_lints/src/misc_early.rs
+++ b/clippy_lints/src/misc_early.rs
@@ -362,61 +362,7 @@ impl EarlyLintPass for MiscEarlyLints {
             }
         }
 
-        if let PatKind::TupleStruct(_, ref patterns) | PatKind::Tuple(ref patterns) = pat.node {
-            fn span_lint(cx: &EarlyContext<'_>, span: Span, only_one: bool) {
-                span_lint_and_sugg(
-                    cx,
-                    UNNEEDED_WILDCARD_PATTERN,
-                    span,
-                    if only_one {
-                        "this pattern is unneeded as the `..` pattern can match that element"
-                    } else {
-                        "these patterns are unneeded as the `..` pattern can match those elements"
-                    },
-                    if only_one { "remove it" } else { "remove them" },
-                    "".to_string(),
-                    Applicability::MachineApplicable,
-                );
-            }
-
-            fn is_rest<P: std::ops::Deref<Target = Pat>>(pat: &P) -> bool {
-                if let PatKind::Rest = pat.node {
-                    true
-                } else {
-                    false
-                }
-            }
-
-            fn is_wild<P: std::ops::Deref<Target = Pat>>(pat: &&P) -> bool {
-                if let PatKind::Wild = pat.node {
-                    true
-                } else {
-                    false
-                }
-            }
-
-            if let Some(rest_index) = patterns.iter().position(is_rest) {
-                if let Some((left_index, left_pat)) = patterns[..rest_index]
-                    .iter()
-                    .rev()
-                    .take_while(is_wild)
-                    .enumerate()
-                    .last()
-                {
-                    span_lint(cx, left_pat.span.until(patterns[rest_index].span), left_index == 0);
-                }
-
-                if let Some((right_index, right_pat)) =
-                    patterns[rest_index + 1..].iter().take_while(is_wild).enumerate().last()
-                {
-                    span_lint(
-                        cx,
-                        patterns[rest_index].span.shrink_to_hi().to(right_pat.span),
-                        right_index == 0,
-                    );
-                }
-            }
-        }
+        check_unneeded_wildcard_pattern(cx, pat);
     }
 
     fn check_fn(&mut self, cx: &EarlyContext<'_>, _: FnKind<'_>, decl: &FnDecl, _: Span, _: NodeId) {
@@ -611,3 +557,62 @@ impl MiscEarlyLints {
         }
     }
 }
+
+fn check_unneeded_wildcard_pattern(cx: &EarlyContext<'_>, pat: &Pat) {
+    if let PatKind::TupleStruct(_, ref patterns) | PatKind::Tuple(ref patterns) = pat.node {
+        fn span_lint(cx: &EarlyContext<'_>, span: Span, only_one: bool) {
+            span_lint_and_sugg(
+                cx,
+                UNNEEDED_WILDCARD_PATTERN,
+                span,
+                if only_one {
+                    "this pattern is unneeded as the `..` pattern can match that element"
+                } else {
+                    "these patterns are unneeded as the `..` pattern can match those elements"
+                },
+                if only_one { "remove it" } else { "remove them" },
+                "".to_string(),
+                Applicability::MachineApplicable,
+            );
+        }
+
+        fn is_rest<P: std::ops::Deref<Target = Pat>>(pat: &P) -> bool {
+            if let PatKind::Rest = pat.node {
+                true
+            } else {
+                false
+            }
+        }
+
+        #[allow(clippy::trivially_copy_pass_by_ref)]
+        fn is_wild<P: std::ops::Deref<Target = Pat>>(pat: &&P) -> bool {
+            if let PatKind::Wild = pat.node {
+                true
+            } else {
+                false
+            }
+        }
+
+        if let Some(rest_index) = patterns.iter().position(is_rest) {
+            if let Some((left_index, left_pat)) = patterns[..rest_index]
+                .iter()
+                .rev()
+                .take_while(is_wild)
+                .enumerate()
+                .last()
+            {
+                span_lint(cx, left_pat.span.until(patterns[rest_index].span), left_index == 0);
+            }
+
+            if let Some((right_index, right_pat)) =
+                patterns[rest_index + 1..].iter().take_while(is_wild).enumerate().last()
+            {
+                span_lint(
+                    cx,
+                    patterns[rest_index].span.shrink_to_hi().to(right_pat.span),
+                    right_index == 0,
+                );
+            }
+        }
+    }
+}
diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs
index 576446d35a7..22129a3abb9 100644
--- a/clippy_lints/src/no_effect.rs
+++ b/clippy_lints/src/no_effect.rs
@@ -47,7 +47,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
         return false;
     }
     match expr.node {
-        ExprKind::Lit(..) | ExprKind::Closure(.., _) => true,
+        ExprKind::Lit(..) | ExprKind::Closure(..) => true,
         ExprKind::Path(..) => !has_drop(cx, cx.tables.expr_ty(expr)),
         ExprKind::Index(ref a, ref b) | ExprKind::Binary(_, ref a, ref b) => {
             has_no_effect(cx, a) && has_no_effect(cx, b)
diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs
index b1b5791b15d..249df8e0e23 100644
--- a/clippy_lints/src/utils/sugg.rs
+++ b/clippy_lints/src/utils/sugg.rs
@@ -93,7 +93,7 @@ impl<'a> Sugg<'a> {
         match expr.node {
             hir::ExprKind::AddrOf(..)
             | hir::ExprKind::Box(..)
-            | hir::ExprKind::Closure(.., _)
+            | hir::ExprKind::Closure(..)
             | hir::ExprKind::Unary(..)
             | hir::ExprKind::Match(..) => Sugg::MaybeParen(snippet),
             hir::ExprKind::Continue(..)