@@ -4,17 +4,16 @@ use clippy_utils::diagnostics::{
4
4
} ;
5
5
use clippy_utils:: macros:: { is_panic, root_macro_call} ;
6
6
use clippy_utils:: peel_blocks_with_stmt;
7
- use clippy_utils:: source:: { expr_block , indent_of, snippet, snippet_block, snippet_opt, snippet_with_applicability} ;
7
+ use clippy_utils:: source:: { indent_of, snippet, snippet_block, snippet_opt, snippet_with_applicability} ;
8
8
use clippy_utils:: sugg:: Sugg ;
9
9
use clippy_utils:: ty:: is_type_diagnostic_item;
10
10
use clippy_utils:: visitors:: is_local_used;
11
11
use clippy_utils:: {
12
- get_parent_expr, is_lang_ctor, is_refutable, is_unit_expr , is_wild, meets_msrv, msrvs, path_to_local_id,
13
- peel_blocks , peel_hir_pat_refs, recurse_or_patterns, strip_pat_refs,
12
+ get_parent_expr, is_lang_ctor, is_refutable, is_wild, meets_msrv, msrvs, path_to_local_id, peel_blocks ,
13
+ peel_hir_pat_refs, recurse_or_patterns, strip_pat_refs,
14
14
} ;
15
15
use core:: iter:: once;
16
16
use if_chain:: if_chain;
17
- use rustc_ast:: ast:: LitKind ;
18
17
use rustc_errors:: Applicability ;
19
18
use rustc_hir:: def:: { CtorKind , DefKind , Res } ;
20
19
use rustc_hir:: LangItem :: { OptionNone , OptionSome } ;
@@ -29,6 +28,7 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
29
28
use rustc_span:: { sym, symbol:: kw, Span } ;
30
29
use std:: cmp:: Ordering ;
31
30
31
+ mod match_bool;
32
32
mod match_like_matches;
33
33
mod match_same_arms;
34
34
mod redundant_pattern_match;
@@ -631,7 +631,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
631
631
632
632
if let ExprKind :: Match ( ex, arms, MatchSource :: Normal ) = expr. kind {
633
633
single_match:: check ( cx, ex, arms, expr) ;
634
- check_match_bool ( cx, ex, arms, expr) ;
634
+ match_bool :: check ( cx, ex, arms, expr) ;
635
635
check_overlapping_arms ( cx, ex, arms) ;
636
636
check_wild_err_arm ( cx, ex, arms) ;
637
637
check_wild_enum_match ( cx, ex, arms) ;
@@ -710,70 +710,6 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
710
710
extract_msrv_attr ! ( LateContext ) ;
711
711
}
712
712
713
- fn check_match_bool ( cx : & LateContext < ' _ > , ex : & Expr < ' _ > , arms : & [ Arm < ' _ > ] , expr : & Expr < ' _ > ) {
714
- // Type of expression is `bool`.
715
- if * cx. typeck_results ( ) . expr_ty ( ex) . kind ( ) == ty:: Bool {
716
- span_lint_and_then (
717
- cx,
718
- MATCH_BOOL ,
719
- expr. span ,
720
- "you seem to be trying to match on a boolean expression" ,
721
- move |diag| {
722
- if arms. len ( ) == 2 {
723
- // no guards
724
- let exprs = if let PatKind :: Lit ( arm_bool) = arms[ 0 ] . pat . kind {
725
- if let ExprKind :: Lit ( ref lit) = arm_bool. kind {
726
- match lit. node {
727
- LitKind :: Bool ( true ) => Some ( ( & * arms[ 0 ] . body , & * arms[ 1 ] . body ) ) ,
728
- LitKind :: Bool ( false ) => Some ( ( & * arms[ 1 ] . body , & * arms[ 0 ] . body ) ) ,
729
- _ => None ,
730
- }
731
- } else {
732
- None
733
- }
734
- } else {
735
- None
736
- } ;
737
-
738
- if let Some ( ( true_expr, false_expr) ) = exprs {
739
- let sugg = match ( is_unit_expr ( true_expr) , is_unit_expr ( false_expr) ) {
740
- ( false , false ) => Some ( format ! (
741
- "if {} {} else {}" ,
742
- snippet( cx, ex. span, "b" ) ,
743
- expr_block( cx, true_expr, None , ".." , Some ( expr. span) ) ,
744
- expr_block( cx, false_expr, None , ".." , Some ( expr. span) )
745
- ) ) ,
746
- ( false , true ) => Some ( format ! (
747
- "if {} {}" ,
748
- snippet( cx, ex. span, "b" ) ,
749
- expr_block( cx, true_expr, None , ".." , Some ( expr. span) )
750
- ) ) ,
751
- ( true , false ) => {
752
- let test = Sugg :: hir ( cx, ex, ".." ) ;
753
- Some ( format ! (
754
- "if {} {}" ,
755
- !test,
756
- expr_block( cx, false_expr, None , ".." , Some ( expr. span) )
757
- ) )
758
- } ,
759
- ( true , true ) => None ,
760
- } ;
761
-
762
- if let Some ( sugg) = sugg {
763
- diag. span_suggestion (
764
- expr. span ,
765
- "consider using an `if`/`else` expression" ,
766
- sugg,
767
- Applicability :: HasPlaceholders ,
768
- ) ;
769
- }
770
- }
771
- }
772
- } ,
773
- ) ;
774
- }
775
- }
776
-
777
713
fn check_overlapping_arms < ' tcx > ( cx : & LateContext < ' tcx > , ex : & ' tcx Expr < ' _ > , arms : & ' tcx [ Arm < ' _ > ] ) {
778
714
if arms. len ( ) >= 2 && cx. typeck_results ( ) . expr_ty ( ex) . is_integral ( ) {
779
715
let ranges = all_ranges ( cx, arms, cx. typeck_results ( ) . expr_ty ( ex) ) ;
0 commit comments