@@ -9,6 +9,7 @@ mod get_unwrap;
9
9
mod implicit_clone;
10
10
mod inefficient_to_string;
11
11
mod inspect_for_each;
12
+ mod into_iter_on_ref;
12
13
mod iter_cloned_collect;
13
14
mod iter_count;
14
15
mod iter_next_slice;
@@ -21,6 +22,7 @@ mod ok_expect;
21
22
mod option_as_ref_deref;
22
23
mod option_map_unwrap_or;
23
24
mod single_char_insert_string;
25
+ mod single_char_pattern;
24
26
mod single_char_push_string;
25
27
mod skip_while_next;
26
28
mod string_extend_chars;
@@ -53,12 +55,11 @@ use rustc_typeck::hir_ty_to_ty;
53
55
use crate :: utils:: eager_or_lazy:: is_lazyness_candidate;
54
56
use crate :: utils:: usage:: mutated_variables;
55
57
use crate :: utils:: {
56
- contains_return, contains_ty, get_parent_expr, get_trait_def_id, has_iter_method, implements_trait, in_macro,
57
- is_copy, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment, match_def_path, match_qpath,
58
- match_trait_method, match_type, meets_msrv, method_calls, method_chain_args, path_to_local_id, paths,
59
- remove_blocks, return_ty, single_segment_path, snippet, snippet_with_applicability, snippet_with_macro_callsite,
60
- span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, strip_pat_refs, sugg, walk_ptrs_ty_depth,
61
- SpanlessEq ,
58
+ contains_return, contains_ty, get_parent_expr, get_trait_def_id, implements_trait, in_macro, is_copy, is_expn_of,
59
+ is_type_diagnostic_item, iter_input_pats, last_path_segment, match_def_path, match_qpath, match_trait_method,
60
+ match_type, meets_msrv, method_calls, method_chain_args, path_to_local_id, paths, remove_blocks, return_ty,
61
+ single_segment_path, snippet, snippet_with_applicability, snippet_with_macro_callsite, span_lint,
62
+ span_lint_and_help, span_lint_and_sugg, span_lint_and_then, strip_pat_refs, sugg, walk_ptrs_ty_depth, SpanlessEq ,
62
63
} ;
63
64
64
65
declare_clippy_lint ! {
@@ -1789,12 +1790,12 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1789
1790
ty:: Ref ( _, ty, _) if * ty. kind ( ) == ty:: Str => {
1790
1791
for & ( method, pos) in & PATTERN_METHODS {
1791
1792
if method_call. ident . name . as_str ( ) == method && args. len ( ) > pos {
1792
- lint_single_char_pattern ( cx, expr, & args[ pos] ) ;
1793
+ single_char_pattern :: check ( cx, expr, & args[ pos] ) ;
1793
1794
}
1794
1795
}
1795
1796
} ,
1796
1797
ty:: Ref ( ..) if method_call. ident . name == sym:: into_iter => {
1797
- lint_into_iter ( cx, expr, self_ty, * method_span) ;
1798
+ into_iter_on_ref :: check ( cx, expr, self_ty, * method_span) ;
1798
1799
} ,
1799
1800
_ => ( ) ,
1800
1801
}
@@ -3202,22 +3203,6 @@ fn get_hint_if_single_char_arg(
3202
3203
}
3203
3204
}
3204
3205
3205
- /// lint for length-1 `str`s for methods in `PATTERN_METHODS`
3206
- fn lint_single_char_pattern ( cx : & LateContext < ' _ > , _expr : & hir:: Expr < ' _ > , arg : & hir:: Expr < ' _ > ) {
3207
- let mut applicability = Applicability :: MachineApplicable ;
3208
- if let Some ( hint) = get_hint_if_single_char_arg ( cx, arg, & mut applicability) {
3209
- span_lint_and_sugg (
3210
- cx,
3211
- SINGLE_CHAR_PATTERN ,
3212
- arg. span ,
3213
- "single-character string constant used as pattern" ,
3214
- "try using a `char` instead" ,
3215
- hint,
3216
- applicability,
3217
- ) ;
3218
- }
3219
- }
3220
-
3221
3206
/// Checks for the `USELESS_ASREF` lint.
3222
3207
fn lint_asref ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , call_name : & str , as_ref_args : & [ hir:: Expr < ' _ > ] ) {
3223
3208
// when we get here, we've already checked that the call name is "as_ref" or "as_mut"
@@ -3254,40 +3239,6 @@ fn lint_asref(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, as_re
3254
3239
}
3255
3240
}
3256
3241
3257
- fn ty_has_iter_method ( cx : & LateContext < ' _ > , self_ref_ty : Ty < ' _ > ) -> Option < ( Symbol , & ' static str ) > {
3258
- has_iter_method ( cx, self_ref_ty) . map ( |ty_name| {
3259
- let mutbl = match self_ref_ty. kind ( ) {
3260
- ty:: Ref ( _, _, mutbl) => mutbl,
3261
- _ => unreachable ! ( ) ,
3262
- } ;
3263
- let method_name = match mutbl {
3264
- hir:: Mutability :: Not => "iter" ,
3265
- hir:: Mutability :: Mut => "iter_mut" ,
3266
- } ;
3267
- ( ty_name, method_name)
3268
- } )
3269
- }
3270
-
3271
- fn lint_into_iter ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , self_ref_ty : Ty < ' _ > , method_span : Span ) {
3272
- if !match_trait_method ( cx, expr, & paths:: INTO_ITERATOR ) {
3273
- return ;
3274
- }
3275
- if let Some ( ( kind, method_name) ) = ty_has_iter_method ( cx, self_ref_ty) {
3276
- span_lint_and_sugg (
3277
- cx,
3278
- INTO_ITER_ON_REF ,
3279
- method_span,
3280
- & format ! (
3281
- "this `.into_iter()` call is equivalent to `.{}()` and will not consume the `{}`" ,
3282
- method_name, kind,
3283
- ) ,
3284
- "call directly" ,
3285
- method_name. to_string ( ) ,
3286
- Applicability :: MachineApplicable ,
3287
- ) ;
3288
- }
3289
- }
3290
-
3291
3242
const FN_HEADER : hir:: FnHeader = hir:: FnHeader {
3292
3243
unsafety : hir:: Unsafety :: Normal ,
3293
3244
constness : hir:: Constness :: NotConst ,
0 commit comments