about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/misc_early/mod.rs29
-rw-r--r--clippy_lints/src/misc_early/redundant_pattern.rs31
2 files changed, 34 insertions, 26 deletions
diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs
index 47cc87dfffb..564afdb7f8d 100644
--- a/clippy_lints/src/misc_early/mod.rs
+++ b/clippy_lints/src/misc_early/mod.rs
@@ -1,11 +1,10 @@
 mod builtin_type_shadow;
 mod double_neg;
+mod redundant_pattern;
 
 use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
 use clippy_utils::source::snippet_opt;
-use rustc_ast::ast::{
-    BindingMode, Expr, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, NodeId, Pat, PatKind,
-};
+use rustc_ast::ast::{Expr, Generics, Lit, LitFloatType, LitIntType, LitKind, NodeId, Pat, PatKind};
 use rustc_ast::visit::FnKind;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_errors::Applicability;
@@ -336,29 +335,7 @@ impl EarlyLintPass for MiscEarlyLints {
             }
         }
 
-        if let PatKind::Ident(left, ident, Some(ref right)) = pat.kind {
-            let left_binding = match left {
-                BindingMode::ByRef(Mutability::Mut) => "ref mut ",
-                BindingMode::ByRef(Mutability::Not) => "ref ",
-                BindingMode::ByValue(..) => "",
-            };
-
-            if let PatKind::Wild = right.kind {
-                span_lint_and_sugg(
-                    cx,
-                    REDUNDANT_PATTERN,
-                    pat.span,
-                    &format!(
-                        "the `{} @ _` pattern can be written as just `{}`",
-                        ident.name, ident.name,
-                    ),
-                    "try",
-                    format!("{}{}", left_binding, ident.name),
-                    Applicability::MachineApplicable,
-                );
-            }
-        }
-
+        redundant_pattern::check(cx, pat);
         check_unneeded_wildcard_pattern(cx, pat);
     }
 
diff --git a/clippy_lints/src/misc_early/redundant_pattern.rs b/clippy_lints/src/misc_early/redundant_pattern.rs
new file mode 100644
index 00000000000..525dbf7757c
--- /dev/null
+++ b/clippy_lints/src/misc_early/redundant_pattern.rs
@@ -0,0 +1,31 @@
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use rustc_ast::ast::{BindingMode, Mutability, Pat, PatKind};
+use rustc_errors::Applicability;
+use rustc_lint::EarlyContext;
+
+use super::REDUNDANT_PATTERN;
+
+pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) {
+    if let PatKind::Ident(left, ident, Some(ref right)) = pat.kind {
+        let left_binding = match left {
+            BindingMode::ByRef(Mutability::Mut) => "ref mut ",
+            BindingMode::ByRef(Mutability::Not) => "ref ",
+            BindingMode::ByValue(..) => "",
+        };
+
+        if let PatKind::Wild = right.kind {
+            span_lint_and_sugg(
+                cx,
+                REDUNDANT_PATTERN,
+                pat.span,
+                &format!(
+                    "the `{} @ _` pattern can be written as just `{}`",
+                    ident.name, ident.name,
+                ),
+                "try",
+                format!("{}{}", left_binding, ident.name),
+                Applicability::MachineApplicable,
+            );
+        }
+    }
+}