1
1
mod bind_instead_of_map;
2
2
mod bytes_nth;
3
3
mod chars_cmp;
4
+ mod chars_cmp_with_unwrap;
5
+ mod chars_last_cmp;
4
6
mod chars_next_cmp;
7
+ mod chars_next_cmp_with_unwrap;
5
8
mod clone_on_copy;
6
9
mod clone_on_ref_ptr;
7
10
mod expect_fun_call;
@@ -54,7 +57,7 @@ mod wrong_self_convention;
54
57
mod zst_offset;
55
58
56
59
use bind_instead_of_map:: BindInsteadOfMap ;
57
- use clippy_utils:: diagnostics:: { span_lint, span_lint_and_help, span_lint_and_sugg } ;
60
+ use clippy_utils:: diagnostics:: { span_lint, span_lint_and_help} ;
58
61
use clippy_utils:: source:: snippet_with_applicability;
59
62
use clippy_utils:: ty:: { contains_ty, implements_trait, is_copy, is_type_diagnostic_item} ;
60
63
use clippy_utils:: {
@@ -66,7 +69,7 @@ use rustc_ast::ast;
66
69
use rustc_errors:: Applicability ;
67
70
use rustc_hir as hir;
68
71
use rustc_hir:: { TraitItem , TraitItemKind } ;
69
- use rustc_lint:: { LateContext , LateLintPass , Lint , LintContext } ;
72
+ use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
70
73
use rustc_middle:: lint:: in_external_macro;
71
74
use rustc_middle:: ty:: { self , TraitRef , Ty , TyS } ;
72
75
use rustc_semver:: RustcVersion ;
@@ -2037,66 +2040,17 @@ fn lint_binary_expr_with_method_call(cx: &LateContext<'_>, info: &mut BinaryExpr
2037
2040
}
2038
2041
2039
2042
lint_with_both_lhs_and_rhs ! ( chars_next_cmp:: check, cx, info) ;
2040
- lint_with_both_lhs_and_rhs ! ( lint_chars_last_cmp , cx, info) ;
2041
- lint_with_both_lhs_and_rhs ! ( lint_chars_next_cmp_with_unwrap , cx, info) ;
2043
+ lint_with_both_lhs_and_rhs ! ( chars_last_cmp :: check , cx, info) ;
2044
+ lint_with_both_lhs_and_rhs ! ( chars_next_cmp_with_unwrap :: check , cx, info) ;
2042
2045
lint_with_both_lhs_and_rhs ! ( lint_chars_last_cmp_with_unwrap, cx, info) ;
2043
2046
}
2044
2047
2045
- /// Checks for the `CHARS_LAST_CMP` lint.
2046
- fn lint_chars_last_cmp < ' tcx > ( cx : & LateContext < ' tcx > , info : & BinaryExprInfo < ' _ > ) -> bool {
2047
- if chars_cmp:: check ( cx, info, & [ "chars" , "last" ] , CHARS_LAST_CMP , "ends_with" ) {
2048
- true
2049
- } else {
2050
- chars_cmp:: check ( cx, info, & [ "chars" , "next_back" ] , CHARS_LAST_CMP , "ends_with" )
2051
- }
2052
- }
2053
-
2054
- /// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints with `unwrap()`.
2055
- fn lint_chars_cmp_with_unwrap < ' tcx > (
2056
- cx : & LateContext < ' tcx > ,
2057
- info : & BinaryExprInfo < ' _ > ,
2058
- chain_methods : & [ & str ] ,
2059
- lint : & ' static Lint ,
2060
- suggest : & str ,
2061
- ) -> bool {
2062
- if_chain ! {
2063
- if let Some ( args) = method_chain_args( info. chain, chain_methods) ;
2064
- if let hir:: ExprKind :: Lit ( ref lit) = info. other. kind;
2065
- if let ast:: LitKind :: Char ( c) = lit. node;
2066
- then {
2067
- let mut applicability = Applicability :: MachineApplicable ;
2068
- span_lint_and_sugg(
2069
- cx,
2070
- lint,
2071
- info. expr. span,
2072
- & format!( "you should use the `{}` method" , suggest) ,
2073
- "like this" ,
2074
- format!( "{}{}.{}('{}')" ,
2075
- if info. eq { "" } else { "!" } ,
2076
- snippet_with_applicability( cx, args[ 0 ] [ 0 ] . span, ".." , & mut applicability) ,
2077
- suggest,
2078
- c) ,
2079
- applicability,
2080
- ) ;
2081
-
2082
- true
2083
- } else {
2084
- false
2085
- }
2086
- }
2087
- }
2088
-
2089
- /// Checks for the `CHARS_NEXT_CMP` lint with `unwrap()`.
2090
- fn lint_chars_next_cmp_with_unwrap < ' tcx > ( cx : & LateContext < ' tcx > , info : & BinaryExprInfo < ' _ > ) -> bool {
2091
- lint_chars_cmp_with_unwrap ( cx, info, & [ "chars" , "next" , "unwrap" ] , CHARS_NEXT_CMP , "starts_with" )
2092
- }
2093
-
2094
2048
/// Checks for the `CHARS_LAST_CMP` lint with `unwrap()`.
2095
2049
fn lint_chars_last_cmp_with_unwrap < ' tcx > ( cx : & LateContext < ' tcx > , info : & BinaryExprInfo < ' _ > ) -> bool {
2096
- if lint_chars_cmp_with_unwrap ( cx, info, & [ "chars" , "last" , "unwrap" ] , CHARS_LAST_CMP , "ends_with" ) {
2050
+ if chars_cmp_with_unwrap :: check ( cx, info, & [ "chars" , "last" , "unwrap" ] , CHARS_LAST_CMP , "ends_with" ) {
2097
2051
true
2098
2052
} else {
2099
- lint_chars_cmp_with_unwrap ( cx, info, & [ "chars" , "next_back" , "unwrap" ] , CHARS_LAST_CMP , "ends_with" )
2053
+ chars_cmp_with_unwrap :: check ( cx, info, & [ "chars" , "next_back" , "unwrap" ] , CHARS_LAST_CMP , "ends_with" )
2100
2054
}
2101
2055
}
2102
2056
0 commit comments