@@ -23,7 +23,7 @@ use rustc_semver::RustcVersion;
2323use rustc_session:: { declare_lint_pass, declare_tool_lint, impl_lint_pass} ;
2424use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
2525use rustc_span:: source_map:: Span ;
26- use rustc_span:: symbol:: { sym, Symbol } ;
26+ use rustc_span:: symbol:: sym;
2727use rustc_target:: abi:: LayoutOf ;
2828use rustc_target:: spec:: abi:: Abi ;
2929use rustc_typeck:: hir_ty_to_ty;
@@ -33,10 +33,10 @@ use crate::utils::paths;
3333use crate :: utils:: sugg:: Sugg ;
3434use crate :: utils:: {
3535 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,
4040} ;
4141
4242declare_clippy_lint ! {
@@ -287,51 +287,12 @@ impl<'tcx> LateLintPass<'tcx> for Types {
287287 }
288288}
289289
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-
329290fn match_buffer_type ( cx : & LateContext < ' _ > , qpath : & QPath < ' _ > ) -> Option < & ' static str > {
330291 if is_ty_param_diagnostic_item ( cx, qpath, sym:: string_type) . is_some ( ) {
331292 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 ( ) {
333294 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 ( ) {
335296 Some ( "std::path::Path" )
336297 } else {
337298 None
0 commit comments