@@ -6,6 +6,7 @@ use std::fmt;
6
6
use std:: iter;
7
7
8
8
use if_chain:: if_chain;
9
+ use lazy_static:: lazy_static;
9
10
use matches:: matches;
10
11
use rustc:: hir;
11
12
use rustc:: hir:: def:: { DefKind , Res } ;
@@ -16,18 +17,16 @@ use rustc_errors::Applicability;
16
17
use syntax:: ast;
17
18
use syntax:: source_map:: { BytePos , Span } ;
18
19
use syntax:: symbol:: { LocalInternedString , Symbol } ;
19
- use lazy_static:: lazy_static;
20
20
21
21
use crate :: utils:: paths;
22
22
use crate :: utils:: sugg;
23
23
use crate :: utils:: sym;
24
24
use crate :: utils:: {
25
25
get_arg_name, get_parent_expr, get_trait_def_id, has_iter_method, implements_trait, in_macro, is_copy,
26
- is_ctor_function, is_expn_of, is_self, is_self_ty, iter_input_pats, last_path_segment, match_path , match_qpath ,
27
- match_trait_method, match_type, match_var, method_calls, method_chain_args, remove_blocks, return_ty, same_tys ,
28
- single_segment_path, snippet, snippet_with_applicability, snippet_with_macro_callsite, span_lint,
26
+ is_ctor_function, is_expn_of, is_self, is_self_ty, iter_input_pats, last_path_segment, match_def_path , match_path ,
27
+ match_qpath , match_trait_method, match_type, match_var, method_calls, method_chain_args, remove_blocks, return_ty,
28
+ same_tys , single_segment_path, snippet, snippet_with_applicability, snippet_with_macro_callsite, span_lint,
29
29
span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq ,
30
- match_def_path,
31
30
} ;
32
31
33
32
declare_clippy_lint ! {
@@ -1068,7 +1067,8 @@ fn lint_or_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: Spa
1068
1067
1069
1068
if [ "default" , "new" ] . contains ( & path) {
1070
1069
let arg_ty = cx. tables . expr_ty ( arg) ;
1071
- let default_trait_id = if let Some ( default_trait_id) = get_trait_def_id ( cx, & * paths:: DEFAULT_TRAIT ) {
1070
+ let default_trait_id = if let Some ( default_trait_id) = get_trait_def_id ( cx, & * paths:: DEFAULT_TRAIT )
1071
+ {
1072
1072
default_trait_id
1073
1073
} else {
1074
1074
return false ;
@@ -2216,15 +2216,33 @@ fn lint_chars_cmp_with_unwrap<'a, 'tcx>(
2216
2216
2217
2217
/// Checks for the `CHARS_NEXT_CMP` lint with `unwrap()`.
2218
2218
fn lint_chars_next_cmp_with_unwrap < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , info : & BinaryExprInfo < ' _ > ) -> bool {
2219
- lint_chars_cmp_with_unwrap ( cx, info, & [ * sym:: chars, * sym:: next, * sym:: unwrap] , CHARS_NEXT_CMP , "starts_with" )
2219
+ lint_chars_cmp_with_unwrap (
2220
+ cx,
2221
+ info,
2222
+ & [ * sym:: chars, * sym:: next, * sym:: unwrap] ,
2223
+ CHARS_NEXT_CMP ,
2224
+ "starts_with" ,
2225
+ )
2220
2226
}
2221
2227
2222
2228
/// Checks for the `CHARS_LAST_CMP` lint with `unwrap()`.
2223
2229
fn lint_chars_last_cmp_with_unwrap < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , info : & BinaryExprInfo < ' _ > ) -> bool {
2224
- if lint_chars_cmp_with_unwrap ( cx, info, & [ * sym:: chars, * sym:: last, * sym:: unwrap] , CHARS_LAST_CMP , "ends_with" ) {
2230
+ if lint_chars_cmp_with_unwrap (
2231
+ cx,
2232
+ info,
2233
+ & [ * sym:: chars, * sym:: last, * sym:: unwrap] ,
2234
+ CHARS_LAST_CMP ,
2235
+ "ends_with" ,
2236
+ ) {
2225
2237
true
2226
2238
} else {
2227
- lint_chars_cmp_with_unwrap ( cx, info, & [ * sym:: chars, * sym:: next_back, * sym:: unwrap] , CHARS_LAST_CMP , "ends_with" )
2239
+ lint_chars_cmp_with_unwrap (
2240
+ cx,
2241
+ info,
2242
+ & [ * sym:: chars, * sym:: next_back, * sym:: unwrap] ,
2243
+ CHARS_LAST_CMP ,
2244
+ "ends_with" ,
2245
+ )
2228
2246
}
2229
2247
}
2230
2248
@@ -2288,10 +2306,7 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr, call_name: &str, as_re
2288
2306
}
2289
2307
}
2290
2308
2291
- fn ty_has_iter_method (
2292
- cx : & LateContext < ' _ , ' _ > ,
2293
- self_ref_ty : Ty < ' _ > ,
2294
- ) -> Option < ( & ' static Lint , Symbol , & ' static str ) > {
2309
+ fn ty_has_iter_method ( cx : & LateContext < ' _ , ' _ > , self_ref_ty : Ty < ' _ > ) -> Option < ( & ' static Lint , Symbol , & ' static str ) > {
2295
2310
if let Some ( ty_name) = has_iter_method ( cx, self_ref_ty) {
2296
2311
let lint = if ty_name == * sym:: array || ty_name == * sym:: PathBuf {
2297
2312
INTO_ITER_ON_ARRAY
0 commit comments