11use clippy_utils:: diagnostics:: span_lint_and_help;
22use 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 } ;
54use rustc_lint:: { LateContext , LateLintPass } ;
6- use rustc_middle:: ty;
75use rustc_semver:: RustcVersion ;
86use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
97
@@ -18,6 +16,7 @@ mod match_wild_enum;
1816mod match_wild_err_arm;
1917mod overlapping_arms;
2018mod redundant_pattern_match;
19+ mod rest_pat_in_fully_bound_struct;
2120mod single_match;
2221
2322declare_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 ) ;
0 commit comments