Skip to content

Commit aa3af30

Browse files
committed
Split out rest_pat_in_fully_bound_struct
1 parent 6477923 commit aa3af30

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

clippy_lints/src/matches/mod.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::{is_wild, meets_msrv, msrvs};
3-
use if_chain::if_chain;
4-
use rustc_hir::{Arm, Expr, ExprKind, Local, MatchSource, Pat, PatKind, QPath};
3+
use rustc_hir::{Arm, Expr, ExprKind, Local, MatchSource, Pat, PatKind};
54
use rustc_lint::{LateContext, LateLintPass};
6-
use rustc_middle::ty;
75
use rustc_semver::RustcVersion;
86
use rustc_session::{declare_tool_lint, impl_lint_pass};
97

@@ -18,6 +16,7 @@ mod match_wild_enum;
1816
mod match_wild_err_arm;
1917
mod overlapping_arms;
2018
mod redundant_pattern_match;
19+
mod rest_pat_in_fully_bound_struct;
2120
mod single_match;
2221

2322
declare_clippy_lint! {
@@ -640,26 +639,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
640639
}
641640

642641
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
643-
if_chain! {
644-
if !pat.span.from_expansion();
645-
if let PatKind::Struct(QPath::Resolved(_, path), fields, true) = pat.kind;
646-
if let Some(def_id) = path.res.opt_def_id();
647-
let ty = cx.tcx.type_of(def_id);
648-
if let ty::Adt(def, _) = ty.kind();
649-
if def.is_struct() || def.is_union();
650-
if fields.len() == def.non_enum_variant().fields.len();
651-
652-
then {
653-
span_lint_and_help(
654-
cx,
655-
REST_PAT_IN_FULLY_BOUND_STRUCTS,
656-
pat.span,
657-
"unnecessary use of `..` pattern in struct binding. All fields were already bound",
658-
None,
659-
"consider removing `..` from this binding",
660-
);
661-
}
662-
}
642+
rest_pat_in_fully_bound_struct::check(cx, pat);
663643
}
664644

665645
extract_msrv_attr!(LateContext);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use clippy_utils::diagnostics::span_lint_and_help;
2+
use rustc_hir::{Pat, PatKind, QPath};
3+
use rustc_lint::LateContext;
4+
use rustc_middle::ty;
5+
6+
use super::REST_PAT_IN_FULLY_BOUND_STRUCTS;
7+
8+
pub(crate) fn check(cx: &LateContext<'_>, pat: &Pat<'_>) {
9+
if_chain! {
10+
if !pat.span.from_expansion();
11+
if let PatKind::Struct(QPath::Resolved(_, path), fields, true) = pat.kind;
12+
if let Some(def_id) = path.res.opt_def_id();
13+
let ty = cx.tcx.type_of(def_id);
14+
if let ty::Adt(def, _) = ty.kind();
15+
if def.is_struct() || def.is_union();
16+
if fields.len() == def.non_enum_variant().fields.len();
17+
18+
then {
19+
span_lint_and_help(
20+
cx,
21+
REST_PAT_IN_FULLY_BOUND_STRUCTS,
22+
pat.span,
23+
"unnecessary use of `..` pattern in struct binding. All fields were already bound",
24+
None,
25+
"consider removing `..` from this binding",
26+
);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)