@@ -3,7 +3,8 @@ use crate::utils::paths;
33use crate :: utils:: sugg:: Sugg ;
44use crate :: utils:: {
55 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,
78} ;
89use if_chain:: if_chain;
910use rustc:: declare_lint_pass;
@@ -267,7 +268,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
267268 check_wild_err_arm ( cx, ex, arms) ;
268269 check_wild_enum_match ( cx, ex, arms) ;
269270 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) ;
271272 }
272273 if let ExprKind :: Match ( ref ex, ref arms, _) = expr. kind {
273274 check_match_ref_pats ( cx, ex, arms, expr) ;
@@ -686,44 +687,17 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>],
686687 }
687688}
688689
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 < ' _ > ] ) {
700691 for arm in arms {
701692 if let PatKind :: Or ( ref fields) = arm. pat . kind {
702693 // look for multiple fields in this arm that contains at least one Wild pattern
703694 if fields. len ( ) > 1 && fields. iter ( ) . any ( is_wild) {
704- span_lint_and_then (
695+ span_help_and_lint (
705696 cx,
706697 WILDCARD_IN_OR_PATTERNS ,
707698 arm. pat . span ,
708699 "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." ,
727701 ) ;
728702 }
729703 }
0 commit comments