about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2022-02-07 12:57:02 -0500
committerJason Newcomb <jsnewcomb@pm.me>2022-02-07 12:57:02 -0500
commitaa3af30dee07a82cd3fcec5732dc575a4571d392 (patch)
tree3e556c41bf2b10013c09ab8893d7e0f7c5dcedcc
parent64779233238b3dcadae13bdeebac82445c1e8f6d (diff)
downloadrust-aa3af30dee07a82cd3fcec5732dc575a4571d392.tar.gz
rust-aa3af30dee07a82cd3fcec5732dc575a4571d392.zip
Split out `rest_pat_in_fully_bound_struct`
-rw-r--r--clippy_lints/src/matches/mod.rs26
-rw-r--r--clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs29
2 files changed, 32 insertions, 23 deletions
diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs
index 0adfa424ee1..4429065966d 100644
--- a/clippy_lints/src/matches/mod.rs
+++ b/clippy_lints/src/matches/mod.rs
@@ -1,9 +1,7 @@
 use clippy_utils::diagnostics::span_lint_and_help;
 use clippy_utils::{is_wild, meets_msrv, msrvs};
-use if_chain::if_chain;
-use rustc_hir::{Arm, Expr, ExprKind, Local, MatchSource, Pat, PatKind, QPath};
+use rustc_hir::{Arm, Expr, ExprKind, Local, MatchSource, Pat, PatKind};
 use rustc_lint::{LateContext, LateLintPass};
-use rustc_middle::ty;
 use rustc_semver::RustcVersion;
 use rustc_session::{declare_tool_lint, impl_lint_pass};
 
@@ -18,6 +16,7 @@ mod match_wild_enum;
 mod match_wild_err_arm;
 mod overlapping_arms;
 mod redundant_pattern_match;
+mod rest_pat_in_fully_bound_struct;
 mod single_match;
 
 declare_clippy_lint! {
@@ -640,26 +639,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
     }
 
     fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
-        if_chain! {
-            if !pat.span.from_expansion();
-            if let PatKind::Struct(QPath::Resolved(_, path), fields, true) = pat.kind;
-            if let Some(def_id) = path.res.opt_def_id();
-            let ty = cx.tcx.type_of(def_id);
-            if let ty::Adt(def, _) = ty.kind();
-            if def.is_struct() || def.is_union();
-            if fields.len() == def.non_enum_variant().fields.len();
-
-            then {
-                span_lint_and_help(
-                    cx,
-                    REST_PAT_IN_FULLY_BOUND_STRUCTS,
-                    pat.span,
-                    "unnecessary use of `..` pattern in struct binding. All fields were already bound",
-                    None,
-                    "consider removing `..` from this binding",
-                );
-            }
-        }
+        rest_pat_in_fully_bound_struct::check(cx, pat);
     }
 
     extract_msrv_attr!(LateContext);
diff --git a/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs b/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs
new file mode 100644
index 00000000000..5076239a57c
--- /dev/null
+++ b/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs
@@ -0,0 +1,29 @@
+use clippy_utils::diagnostics::span_lint_and_help;
+use rustc_hir::{Pat, PatKind, QPath};
+use rustc_lint::LateContext;
+use rustc_middle::ty;
+
+use super::REST_PAT_IN_FULLY_BOUND_STRUCTS;
+
+pub(crate) fn check(cx: &LateContext<'_>, pat: &Pat<'_>) {
+    if_chain! {
+        if !pat.span.from_expansion();
+        if let PatKind::Struct(QPath::Resolved(_, path), fields, true) = pat.kind;
+        if let Some(def_id) = path.res.opt_def_id();
+        let ty = cx.tcx.type_of(def_id);
+        if let ty::Adt(def, _) = ty.kind();
+        if def.is_struct() || def.is_union();
+        if fields.len() == def.non_enum_variant().fields.len();
+
+        then {
+            span_lint_and_help(
+                cx,
+                REST_PAT_IN_FULLY_BOUND_STRUCTS,
+                pat.span,
+                "unnecessary use of `..` pattern in struct binding. All fields were already bound",
+                None,
+                "consider removing `..` from this binding",
+            );
+        }
+    }
+}