@@ -3,7 +3,10 @@ use super::unnecessary_iter_cloned::{self, is_into_iter};
3
3
use clippy_utils:: diagnostics:: { span_lint_and_sugg, span_lint_and_then} ;
4
4
use clippy_utils:: msrvs:: { self , Msrv } ;
5
5
use clippy_utils:: source:: { SpanRangeExt , snippet} ;
6
- use clippy_utils:: ty:: { get_iterator_item_ty, implements_trait, is_copy, is_type_diagnostic_item, is_type_lang_item} ;
6
+ use clippy_utils:: ty:: {
7
+ get_callee_generic_args_and_args, get_iterator_item_ty, implements_trait, is_copy, is_to_string_on_string_like,
8
+ is_type_diagnostic_item, is_type_lang_item,
9
+ } ;
7
10
use clippy_utils:: visitors:: find_all_ret_expressions;
8
11
use clippy_utils:: {
9
12
fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trait_item, is_expr_temporary_value, peel_middle_ty_refs,
@@ -18,7 +21,7 @@ use rustc_lint::LateContext;
18
21
use rustc_middle:: mir:: Mutability ;
19
22
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , OverloadedDeref } ;
20
23
use rustc_middle:: ty:: {
21
- self , ClauseKind , GenericArg , GenericArgKind , GenericArgsRef , ParamTy , ProjectionPredicate , TraitPredicate , Ty ,
24
+ self , ClauseKind , GenericArg , GenericArgKind , ParamTy , ProjectionPredicate , TraitPredicate , Ty ,
22
25
} ;
23
26
use rustc_span:: Symbol ;
24
27
use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
@@ -443,33 +446,6 @@ fn skip_addr_of_ancestors<'tcx>(
443
446
None
444
447
}
445
448
446
- /// Checks whether an expression is a function or method call and, if so, returns its `DefId`,
447
- /// `GenericArgs`, and arguments.
448
- fn get_callee_generic_args_and_args < ' tcx > (
449
- cx : & LateContext < ' tcx > ,
450
- expr : & ' tcx Expr < ' tcx > ,
451
- ) -> Option < (
452
- DefId ,
453
- GenericArgsRef < ' tcx > ,
454
- Option < & ' tcx Expr < ' tcx > > ,
455
- & ' tcx [ Expr < ' tcx > ] ,
456
- ) > {
457
- if let ExprKind :: Call ( callee, args) = expr. kind
458
- && let callee_ty = cx. typeck_results ( ) . expr_ty ( callee)
459
- && let ty:: FnDef ( callee_def_id, _) = callee_ty. kind ( )
460
- {
461
- let generic_args = cx. typeck_results ( ) . node_args ( callee. hir_id ) ;
462
- return Some ( ( * callee_def_id, generic_args, None , args) ) ;
463
- }
464
- if let ExprKind :: MethodCall ( _, recv, args, _) = expr. kind
465
- && let Some ( method_def_id) = cx. typeck_results ( ) . type_dependent_def_id ( expr. hir_id )
466
- {
467
- let generic_args = cx. typeck_results ( ) . node_args ( expr. hir_id ) ;
468
- return Some ( ( method_def_id, generic_args, Some ( recv) , args) ) ;
469
- }
470
- None
471
- }
472
-
473
449
/// Returns the `TraitPredicate`s and `ProjectionPredicate`s for a function's input type.
474
450
fn get_input_traits_and_projections < ' tcx > (
475
451
cx : & LateContext < ' tcx > ,
@@ -623,40 +599,14 @@ fn is_cloned_or_copied(cx: &LateContext<'_>, method_name: Symbol, method_def_id:
623
599
fn is_to_owned_like < ' a > ( cx : & LateContext < ' a > , call_expr : & Expr < ' a > , method_name : Symbol , method_def_id : DefId ) -> bool {
624
600
is_cow_into_owned ( cx, method_name, method_def_id)
625
601
|| ( method_name != sym:: to_string && is_clone_like ( cx, method_name, method_def_id) )
626
- || is_to_string_on_string_like ( cx, call_expr, method_name , method_def_id)
602
+ || is_to_string_on_string_like ( cx, call_expr, method_def_id)
627
603
}
628
604
629
605
/// Returns true if the named method is `Cow::into_owned`.
630
606
fn is_cow_into_owned ( cx : & LateContext < ' _ > , method_name : Symbol , method_def_id : DefId ) -> bool {
631
607
method_name == sym:: into_owned && is_diag_item_method ( cx, method_def_id, sym:: Cow )
632
608
}
633
609
634
- /// Returns true if the named method is `ToString::to_string` and it's called on a type that
635
- /// is string-like i.e. implements `AsRef<str>` or `Deref<Target = str>`.
636
- fn is_to_string_on_string_like < ' a > (
637
- cx : & LateContext < ' _ > ,
638
- call_expr : & ' a Expr < ' a > ,
639
- method_name : Symbol ,
640
- method_def_id : DefId ,
641
- ) -> bool {
642
- if method_name != sym:: to_string || !is_diag_trait_item ( cx, method_def_id, sym:: ToString ) {
643
- return false ;
644
- }
645
-
646
- if let Some ( args) = cx. typeck_results ( ) . node_args_opt ( call_expr. hir_id )
647
- && let [ generic_arg] = args. as_slice ( )
648
- && let GenericArgKind :: Type ( ty) = generic_arg. kind ( )
649
- && let Some ( deref_trait_id) = cx. tcx . get_diagnostic_item ( sym:: Deref )
650
- && let Some ( as_ref_trait_id) = cx. tcx . get_diagnostic_item ( sym:: AsRef )
651
- && ( cx. get_associated_type ( ty, deref_trait_id, sym:: Target ) == Some ( cx. tcx . types . str_ )
652
- || implements_trait ( cx, ty, as_ref_trait_id, & [ cx. tcx . types . str_ . into ( ) ] ) )
653
- {
654
- true
655
- } else {
656
- false
657
- }
658
- }
659
-
660
610
fn std_map_key < ' tcx > ( cx : & LateContext < ' tcx > , ty : Ty < ' tcx > ) -> Option < Ty < ' tcx > > {
661
611
match ty. kind ( ) {
662
612
ty:: Adt ( adt, args)
0 commit comments