@@ -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, get_qpath_generic_tys, higher, in_constant, indent_of, int_bits,
36
- is_hir_ty_cfg_dependant, is_type_diagnostic_item , last_path_segment , match_def_path , match_path , meets_msrv ,
37
- method_chain_args , 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_hir_ty_cfg_dependant, is_ty_param_diagnostic_item , is_ty_param_lang_item , is_type_diagnostic_item ,
37
+ last_path_segment , match_def_path , match_path , meets_msrv , method_chain_args , multispan_sugg ,
38
+ numeric_literal :: NumericLiteral , reindent_multiline , sext , snippet , snippet_opt , snippet_with_applicability ,
39
+ snippet_with_macro_callsite , span_lint , span_lint_and_help , span_lint_and_sugg , span_lint_and_then, unsext,
40
40
} ;
41
41
42
42
declare_clippy_lint ! {
@@ -287,51 +287,12 @@ impl<'tcx> LateLintPass<'tcx> for Types {
287
287
}
288
288
}
289
289
290
- /// Checks if the first type parameter is a lang item.
291
- fn is_ty_param_lang_item ( cx : & LateContext < ' _ > , qpath : & QPath < ' tcx > , item : LangItem ) -> Option < & ' tcx hir:: Ty < ' tcx > > {
292
- let ty = get_qpath_generic_tys ( qpath) . next ( ) ?;
293
-
294
- if let TyKind :: Path ( qpath) = & ty. kind {
295
- cx. qpath_res ( qpath, ty. hir_id )
296
- . opt_def_id ( )
297
- . and_then ( |id| ( cx. tcx . lang_items ( ) . require ( item) == Ok ( id) ) . then ( || ty) )
298
- } else {
299
- None
300
- }
301
- }
302
-
303
- /// Checks if the first type parameter is a diagnostic item.
304
- fn is_ty_param_diagnostic_item ( cx : & LateContext < ' _ > , qpath : & QPath < ' tcx > , item : Symbol ) -> Option < & ' tcx hir:: Ty < ' tcx > > {
305
- let ty = get_qpath_generic_tys ( qpath) . next ( ) ?;
306
-
307
- if let TyKind :: Path ( qpath) = & ty. kind {
308
- cx. qpath_res ( qpath, ty. hir_id )
309
- . opt_def_id ( )
310
- . and_then ( |id| cx. tcx . is_diagnostic_item ( item, id) . then ( || ty) )
311
- } else {
312
- None
313
- }
314
- }
315
-
316
- /// Checks if the first type parameter is a given item.
317
- fn is_ty_param_path ( cx : & LateContext < ' _ > , qpath : & QPath < ' tcx > , path : & [ & str ] ) -> Option < & ' tcx hir:: Ty < ' tcx > > {
318
- let ty = get_qpath_generic_tys ( qpath) . next ( ) ?;
319
-
320
- if let TyKind :: Path ( qpath) = & ty. kind {
321
- cx. qpath_res ( qpath, ty. hir_id )
322
- . opt_def_id ( )
323
- . and_then ( |id| match_def_path ( cx, id, path) . then ( || ty) )
324
- } else {
325
- None
326
- }
327
- }
328
-
329
290
fn match_buffer_type ( cx : & LateContext < ' _ > , qpath : & QPath < ' _ > ) -> Option < & ' static str > {
330
291
if is_ty_param_diagnostic_item ( cx, qpath, sym:: string_type) . is_some ( ) {
331
292
Some ( "str" )
332
- } else if is_ty_param_path ( cx, qpath, & paths :: OS_STRING ) . is_some ( ) {
293
+ } else if is_ty_param_diagnostic_item ( cx, qpath, sym :: OsString ) . is_some ( ) {
333
294
Some ( "std::ffi::OsStr" )
334
- } else if is_ty_param_path ( cx, qpath, & paths :: PATH_BUF ) . is_some ( ) {
295
+ } else if is_ty_param_diagnostic_item ( cx, qpath, sym :: PathBuf ) . is_some ( ) {
335
296
Some ( "std::path::Path" )
336
297
} else {
337
298
None
0 commit comments