1
- use clippy_utils:: diagnostics:: {
2
- multispan_sugg, span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then,
3
- } ;
4
- use clippy_utils:: macros:: { is_panic, root_macro_call} ;
5
- use clippy_utils:: peel_blocks_with_stmt;
1
+ use clippy_utils:: diagnostics:: { multispan_sugg, span_lint_and_help, span_lint_and_sugg, span_lint_and_then} ;
6
2
use clippy_utils:: source:: { indent_of, snippet, snippet_block, snippet_opt, snippet_with_applicability} ;
7
3
use clippy_utils:: sugg:: Sugg ;
8
4
use clippy_utils:: ty:: is_type_diagnostic_item;
9
- use clippy_utils:: visitors:: is_local_used;
10
5
use clippy_utils:: {
11
6
get_parent_expr, is_lang_ctor, is_refutable, is_wild, meets_msrv, msrvs, path_to_local_id, peel_blocks,
12
7
peel_hir_pat_refs, recurse_or_patterns, strip_pat_refs,
@@ -24,11 +19,12 @@ use rustc_lint::{LateContext, LateLintPass};
24
19
use rustc_middle:: ty:: { self , VariantDef } ;
25
20
use rustc_semver:: RustcVersion ;
26
21
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
27
- use rustc_span:: { sym, symbol :: kw } ;
22
+ use rustc_span:: sym;
28
23
29
24
mod match_bool;
30
25
mod match_like_matches;
31
26
mod match_same_arms;
27
+ mod match_wild_err_arm;
32
28
mod overlapping_arms;
33
29
mod redundant_pattern_match;
34
30
mod single_match;
@@ -632,7 +628,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
632
628
single_match:: check ( cx, ex, arms, expr) ;
633
629
match_bool:: check ( cx, ex, arms, expr) ;
634
630
overlapping_arms:: check ( cx, ex, arms) ;
635
- check_wild_err_arm ( cx, ex, arms) ;
631
+ match_wild_err_arm :: check ( cx, ex, arms) ;
636
632
check_wild_enum_match ( cx, ex, arms) ;
637
633
check_match_as_ref ( cx, ex, arms, expr) ;
638
634
check_wild_in_or_pats ( cx, arms) ;
@@ -709,47 +705,6 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
709
705
extract_msrv_attr ! ( LateContext ) ;
710
706
}
711
707
712
- fn check_wild_err_arm < ' tcx > ( cx : & LateContext < ' tcx > , ex : & Expr < ' tcx > , arms : & [ Arm < ' tcx > ] ) {
713
- let ex_ty = cx. typeck_results ( ) . expr_ty ( ex) . peel_refs ( ) ;
714
- if is_type_diagnostic_item ( cx, ex_ty, sym:: Result ) {
715
- for arm in arms {
716
- if let PatKind :: TupleStruct ( ref path, inner, _) = arm. pat . kind {
717
- let path_str = rustc_hir_pretty:: to_string ( rustc_hir_pretty:: NO_ANN , |s| s. print_qpath ( path, false ) ) ;
718
- if path_str == "Err" {
719
- let mut matching_wild = inner. iter ( ) . any ( is_wild) ;
720
- let mut ident_bind_name = kw:: Underscore ;
721
- if !matching_wild {
722
- // Looking for unused bindings (i.e.: `_e`)
723
- for pat in inner. iter ( ) {
724
- if let PatKind :: Binding ( _, id, ident, None ) = pat. kind {
725
- if ident. as_str ( ) . starts_with ( '_' ) && !is_local_used ( cx, arm. body , id) {
726
- ident_bind_name = ident. name ;
727
- matching_wild = true ;
728
- }
729
- }
730
- }
731
- }
732
- if_chain ! {
733
- if matching_wild;
734
- if let Some ( macro_call) = root_macro_call( peel_blocks_with_stmt( arm. body) . span) ;
735
- if is_panic( cx, macro_call. def_id) ;
736
- then {
737
- // `Err(_)` or `Err(_e)` arm with `panic!` found
738
- span_lint_and_note( cx,
739
- MATCH_WILD_ERR_ARM ,
740
- arm. pat. span,
741
- & format!( "`Err({})` matches all errors" , ident_bind_name) ,
742
- None ,
743
- "match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable" ,
744
- ) ;
745
- }
746
- }
747
- }
748
- }
749
- }
750
- }
751
- }
752
-
753
708
enum CommonPrefixSearcher < ' a > {
754
709
None ,
755
710
Path ( & ' a [ PathSegment < ' a > ] ) ,
0 commit comments