@@ -23,7 +23,7 @@ use rustc_semver::RustcVersion;
23
23
use rustc_session:: { declare_lint_pass, declare_tool_lint, impl_lint_pass} ;
24
24
use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
25
25
use rustc_span:: source_map:: Span ;
26
- use rustc_span:: symbol:: { sym, Symbol } ;
26
+ use rustc_span:: symbol:: sym;
27
27
use rustc_target:: abi:: LayoutOf ;
28
28
use rustc_target:: spec:: abi:: Abi ;
29
29
use rustc_typeck:: hir_ty_to_ty;
@@ -33,10 +33,10 @@ use crate::utils::paths;
33
33
use crate :: utils:: sugg:: Sugg ;
34
34
use crate :: utils:: {
35
35
clip, comparisons, differing_macro_contexts, higher, in_constant, indent_of, int_bits, is_hir_ty_cfg_dependant,
36
- is_type_diagnostic_item, last_path_segment, match_def_path, match_path, meets_msrv , method_chain_args ,
37
- multispan_sugg, numeric_literal:: NumericLiteral , reindent_multiline, sext, snippet, snippet_opt ,
38
- snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg ,
39
- span_lint_and_then, unsext,
36
+ is_type_diagnostic_item, last_path_segment, match_def_path, match_path, match_type_parameter_diagnostic_item ,
37
+ meets_msrv , method_chain_args , multispan_sugg, numeric_literal:: NumericLiteral , reindent_multiline, sext, snippet,
38
+ snippet_opt , snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help,
39
+ span_lint_and_sugg , span_lint_and_then, unsext,
40
40
} ;
41
41
42
42
declare_clippy_lint ! {
@@ -307,33 +307,14 @@ fn match_type_parameter(cx: &LateContext<'_>, qpath: &QPath<'_>, path: &[&str])
307
307
None
308
308
}
309
309
310
- /// Checks if `qpath` has last segment with type parameter matching `diagnostic`
311
- fn match_type_parameter_diagnostic ( cx : & LateContext < ' _ > , qpath : & QPath < ' _ > , diagnostic : Symbol ) -> Option < Span > {
312
- let last = last_path_segment ( qpath) ;
313
- if_chain ! {
314
- if let Some ( ref params) = last. args;
315
- if !params. parenthesized;
316
- if let Some ( ty) = params. args. iter( ) . find_map( |arg| match arg {
317
- GenericArg :: Type ( ty) => Some ( ty) ,
318
- _ => None ,
319
- } ) ;
320
- if let TyKind :: Path ( ref qpath) = ty. kind;
321
- if cx. qpath_res( qpath, ty. hir_id) . opt_def_id( ) == cx. tcx. get_diagnostic_item( diagnostic) ;
322
- then {
323
- return Some ( ty. span) ;
324
- }
325
- }
326
- None
327
- }
328
-
329
310
fn match_buffer_type ( cx : & LateContext < ' _ > , qpath : & QPath < ' _ > ) -> Option < & ' static str > {
330
- if match_type_parameter_diagnostic ( cx, qpath, sym:: string_type) . is_some ( ) {
311
+ if match_type_parameter_diagnostic_item ( cx, qpath, sym:: string_type) . is_some ( ) {
331
312
return Some ( "str" ) ;
332
313
}
333
- if match_type_parameter_diagnostic ( cx, qpath, sym:: OsString ) . is_some ( ) {
314
+ if match_type_parameter_diagnostic_item ( cx, qpath, sym:: OsString ) . is_some ( ) {
334
315
return Some ( "std::ffi::OsStr" ) ;
335
316
}
336
- if match_type_parameter_diagnostic ( cx, qpath, sym:: PathBuf ) . is_some ( ) {
317
+ if match_type_parameter_diagnostic_item ( cx, qpath, sym:: PathBuf ) . is_some ( ) {
337
318
return Some ( "std::path::Path" ) ;
338
319
}
339
320
None
@@ -400,7 +381,7 @@ impl Types {
400
381
) ;
401
382
return ; // don't recurse into the type
402
383
}
403
- if match_type_parameter_diagnostic ( cx, qpath, sym:: vec_type) . is_some ( ) {
384
+ if match_type_parameter_diagnostic_item ( cx, qpath, sym:: vec_type) . is_some ( ) {
404
385
span_lint_and_help (
405
386
cx,
406
387
BOX_VEC ,
@@ -412,7 +393,7 @@ impl Types {
412
393
return ; // don't recurse into the type
413
394
}
414
395
} else if cx. tcx . is_diagnostic_item ( sym:: Rc , def_id) {
415
- if let Some ( span) = match_type_parameter_diagnostic ( cx, qpath, sym:: Rc ) {
396
+ if let Some ( span) = match_type_parameter_diagnostic_item ( cx, qpath, sym:: Rc ) {
416
397
let mut applicability = Applicability :: MachineApplicable ;
417
398
span_lint_and_sugg (
418
399
cx,
@@ -464,7 +445,7 @@ impl Types {
464
445
) ;
465
446
return ; // don't recurse into the type
466
447
}
467
- if match_type_parameter_diagnostic ( cx, qpath, sym:: vec_type) . is_some ( ) {
448
+ if match_type_parameter_diagnostic_item ( cx, qpath, sym:: vec_type) . is_some ( ) {
468
449
let vec_ty = match & last_path_segment ( qpath) . args . unwrap ( ) . args [ 0 ] {
469
450
GenericArg :: Type ( ty) => match & ty. kind {
470
451
TyKind :: Path ( qpath) => qpath,
@@ -517,7 +498,7 @@ impl Types {
517
498
) ;
518
499
return ; // don't recurse into the type
519
500
}
520
- if match_type_parameter_diagnostic ( cx, qpath, sym:: vec_type) . is_some ( ) {
501
+ if match_type_parameter_diagnostic_item ( cx, qpath, sym:: vec_type) . is_some ( ) {
521
502
let vec_ty = match & last_path_segment ( qpath) . args . unwrap ( ) . args [ 0 ] {
522
503
GenericArg :: Type ( ty) => match & ty. kind {
523
504
TyKind :: Path ( qpath) => qpath,
@@ -582,7 +563,7 @@ impl Types {
582
563
}
583
564
}
584
565
} else if cx. tcx . is_diagnostic_item ( sym:: option_type, def_id) {
585
- if match_type_parameter ( cx, qpath, & paths :: OPTION ) . is_some ( ) {
566
+ if match_type_parameter_diagnostic_item ( cx, qpath, sym :: option_type ) . is_some ( ) {
586
567
span_lint (
587
568
cx,
588
569
OPTION_OPTION ,
0 commit comments