@@ -9,6 +9,7 @@ mod get_unwrap;
99mod implicit_clone;
1010mod inefficient_to_string;
1111mod inspect_for_each;
12+ mod into_iter_on_ref;
1213mod iter_cloned_collect;
1314mod iter_count;
1415mod iter_next_slice;
@@ -21,6 +22,7 @@ mod ok_expect;
2122mod option_as_ref_deref;
2223mod option_map_unwrap_or;
2324mod single_char_insert_string;
25+ mod single_char_pattern;
2426mod single_char_push_string;
2527mod skip_while_next;
2628mod string_extend_chars;
@@ -53,12 +55,11 @@ use rustc_typeck::hir_ty_to_ty;
5355use crate :: utils:: eager_or_lazy:: is_lazyness_candidate;
5456use crate :: utils:: usage:: mutated_variables;
5557use 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 ,
6263} ;
6364
6465declare_clippy_lint ! {
@@ -1789,12 +1790,12 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
17891790 ty:: Ref ( _, ty, _) if * ty. kind ( ) == ty:: Str => {
17901791 for & ( method, pos) in & PATTERN_METHODS {
17911792 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] ) ;
17931794 }
17941795 }
17951796 } ,
17961797 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) ;
17981799 } ,
17991800 _ => ( ) ,
18001801 }
@@ -3202,22 +3203,6 @@ fn get_hint_if_single_char_arg(
32023203 }
32033204}
32043205
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-
32213206/// Checks for the `USELESS_ASREF` lint.
32223207fn lint_asref ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , call_name : & str , as_ref_args : & [ hir:: Expr < ' _ > ] ) {
32233208 // 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
32543239 }
32553240}
32563241
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-
32913242const FN_HEADER : hir:: FnHeader = hir:: FnHeader {
32923243 unsafety : hir:: Unsafety :: Normal ,
32933244 constness : hir:: Constness :: NotConst ,
0 commit comments