@@ -3,7 +3,8 @@ use crate::utils::paths;
3
3
use crate :: utils:: sugg:: Sugg ;
4
4
use crate :: utils:: {
5
5
expr_block, is_allowed, is_expn_of, match_qpath, match_type, multispan_sugg, remove_blocks, snippet,
6
- snippet_with_applicability, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty,
6
+ snippet_with_applicability, span_help_and_lint, span_lint_and_sugg, span_lint_and_then, span_note_and_lint,
7
+ walk_ptrs_ty,
7
8
} ;
8
9
use if_chain:: if_chain;
9
10
use rustc:: declare_lint_pass;
@@ -267,7 +268,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
267
268
check_wild_err_arm ( cx, ex, arms) ;
268
269
check_wild_enum_match ( cx, ex, arms) ;
269
270
check_match_as_ref ( cx, ex, arms, expr) ;
270
- check_wild_in_or_pats ( cx, ex , arms) ;
271
+ check_wild_in_or_pats ( cx, arms) ;
271
272
}
272
273
if let ExprKind :: Match ( ref ex, ref arms, _) = expr. kind {
273
274
check_match_ref_pats ( cx, ex, arms, expr) ;
@@ -686,44 +687,17 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>],
686
687
}
687
688
}
688
689
689
- fn check_wild_in_or_pats ( cx : & LateContext < ' _ , ' _ > , ex : & Expr < ' _ > , arms : & [ Arm < ' _ > ] ) {
690
- let mut is_non_exhaustive_enum = false ;
691
- let ty = cx. tables . expr_ty ( ex) ;
692
- if ty. is_enum ( ) {
693
- if let ty:: Adt ( def, _) = ty. kind {
694
- if def. is_variant_list_non_exhaustive ( ) {
695
- is_non_exhaustive_enum = true ;
696
- }
697
- }
698
- }
699
-
690
+ fn check_wild_in_or_pats ( cx : & LateContext < ' _ , ' _ > , arms : & [ Arm < ' _ > ] ) {
700
691
for arm in arms {
701
692
if let PatKind :: Or ( ref fields) = arm. pat . kind {
702
693
// look for multiple fields in this arm that contains at least one Wild pattern
703
694
if fields. len ( ) > 1 && fields. iter ( ) . any ( is_wild) {
704
- span_lint_and_then (
695
+ span_help_and_lint (
705
696
cx,
706
697
WILDCARD_IN_OR_PATTERNS ,
707
698
arm. pat . span ,
708
699
"wildcard pattern covers any other pattern as it will match anyway." ,
709
- |db| {
710
- // handle case where a non exhaustive enum is being used
711
- if is_non_exhaustive_enum {
712
- db. span_suggestion (
713
- arm. pat . span ,
714
- "consider handling `_` separately." ,
715
- "_ => ..." . to_string ( ) ,
716
- Applicability :: MaybeIncorrect ,
717
- ) ;
718
- } else {
719
- db. span_suggestion (
720
- arm. pat . span ,
721
- "consider replacing with wildcard pattern only" ,
722
- "_" . to_string ( ) ,
723
- Applicability :: MachineApplicable ,
724
- ) ;
725
- }
726
- } ,
700
+ "Consider handling `_` separately." ,
727
701
) ;
728
702
}
729
703
}
0 commit comments