@@ -4,7 +4,10 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
44use clippy_utils:: msrvs:: { self , Msrv } ;
55use clippy_utils:: res:: MaybeDef ;
66use clippy_utils:: source:: { SpanRangeExt , snippet} ;
7- use clippy_utils:: ty:: { get_iterator_item_ty, implements_trait, is_copy, peel_and_count_ty_refs} ;
7+ use clippy_utils:: ty:: {
8+ get_callee_generic_args_and_args, get_iterator_item_ty, implements_trait, is_copy, is_to_string_on_string_like,
9+ peel_and_count_ty_refs,
10+ } ;
811use clippy_utils:: visitors:: find_all_ret_expressions;
912use clippy_utils:: { fn_def_id, get_parent_expr, is_expr_temporary_value, return_ty, sym} ;
1013use rustc_errors:: Applicability ;
@@ -16,7 +19,7 @@ use rustc_lint::LateContext;
1619use rustc_middle:: mir:: Mutability ;
1720use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , OverloadedDeref } ;
1821use rustc_middle:: ty:: {
19- self , ClauseKind , GenericArg , GenericArgKind , GenericArgsRef , ParamTy , ProjectionPredicate , TraitPredicate , Ty ,
22+ self , ClauseKind , GenericArg , GenericArgKind , ParamTy , ProjectionPredicate , TraitPredicate , Ty ,
2023} ;
2124use rustc_span:: Symbol ;
2225use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
@@ -441,33 +444,6 @@ fn skip_addr_of_ancestors<'tcx>(
441444 None
442445}
443446
444- /// Checks whether an expression is a function or method call and, if so, returns its `DefId`,
445- /// `GenericArgs`, and arguments.
446- fn get_callee_generic_args_and_args < ' tcx > (
447- cx : & LateContext < ' tcx > ,
448- expr : & ' tcx Expr < ' tcx > ,
449- ) -> Option < (
450- DefId ,
451- GenericArgsRef < ' tcx > ,
452- Option < & ' tcx Expr < ' tcx > > ,
453- & ' tcx [ Expr < ' tcx > ] ,
454- ) > {
455- if let ExprKind :: Call ( callee, args) = expr. kind
456- && let callee_ty = cx. typeck_results ( ) . expr_ty ( callee)
457- && let ty:: FnDef ( callee_def_id, _) = callee_ty. kind ( )
458- {
459- let generic_args = cx. typeck_results ( ) . node_args ( callee. hir_id ) ;
460- return Some ( ( * callee_def_id, generic_args, None , args) ) ;
461- }
462- if let ExprKind :: MethodCall ( _, recv, args, _) = expr. kind
463- && let Some ( method_def_id) = cx. typeck_results ( ) . type_dependent_def_id ( expr. hir_id )
464- {
465- let generic_args = cx. typeck_results ( ) . node_args ( expr. hir_id ) ;
466- return Some ( ( method_def_id, generic_args, Some ( recv) , args) ) ;
467- }
468- None
469- }
470-
471447/// Returns the `TraitPredicate`s and `ProjectionPredicate`s for a function's input type.
472448fn get_input_traits_and_projections < ' tcx > (
473449 cx : & LateContext < ' tcx > ,
@@ -626,40 +602,14 @@ fn is_to_owned_like<'a>(
626602) -> bool {
627603 is_cow_into_owned ( cx, method_name, method_parent_id)
628604 || ( method_name != sym:: to_string && is_clone_like ( cx, method_name, method_parent_id) )
629- || is_to_string_on_string_like ( cx, call_expr, method_name , method_parent_id)
605+ || is_to_string_on_string_like ( cx, call_expr, method_parent_id)
630606}
631607
632608/// Returns true if the named method is `Cow::into_owned`.
633609fn is_cow_into_owned ( cx : & LateContext < ' _ > , method_name : Symbol , method_parent_id : DefId ) -> bool {
634610 method_name == sym:: into_owned && method_parent_id. opt_impl_ty ( cx) . is_diag_item ( cx, sym:: Cow )
635611}
636612
637- /// Returns true if the named method is `ToString::to_string` and it's called on a type that
638- /// is string-like i.e. implements `AsRef<str>` or `Deref<Target = str>`.
639- fn is_to_string_on_string_like < ' a > (
640- cx : & LateContext < ' _ > ,
641- call_expr : & ' a Expr < ' a > ,
642- method_name : Symbol ,
643- method_parent_id : DefId ,
644- ) -> bool {
645- if method_name != sym:: to_string || !method_parent_id. is_diag_item ( cx, sym:: ToString ) {
646- return false ;
647- }
648-
649- if let Some ( args) = cx. typeck_results ( ) . node_args_opt ( call_expr. hir_id )
650- && let [ generic_arg] = args. as_slice ( )
651- && let GenericArgKind :: Type ( ty) = generic_arg. kind ( )
652- && let Some ( deref_trait_id) = cx. tcx . get_diagnostic_item ( sym:: Deref )
653- && let Some ( as_ref_trait_id) = cx. tcx . get_diagnostic_item ( sym:: AsRef )
654- && ( cx. get_associated_type ( ty, deref_trait_id, sym:: Target ) == Some ( cx. tcx . types . str_ )
655- || implements_trait ( cx, ty, as_ref_trait_id, & [ cx. tcx . types . str_ . into ( ) ] ) )
656- {
657- true
658- } else {
659- false
660- }
661- }
662-
663613fn std_map_key < ' tcx > ( cx : & LateContext < ' tcx > , ty : Ty < ' tcx > ) -> Option < Ty < ' tcx > > {
664614 match ty. kind ( ) {
665615 ty:: Adt ( adt, args)
0 commit comments