@@ -2,9 +2,9 @@ use clippy_config::Conf;
22use clippy_utils:: diagnostics:: span_lint_and_then;
33use clippy_utils:: mir:: { PossibleBorrowerMap , enclosing_mir} ;
44use clippy_utils:: msrvs:: { self , Msrv } ;
5- use clippy_utils:: res:: MaybeResPath ;
5+ use clippy_utils:: res:: { MaybeDef , MaybeResPath } ;
66use clippy_utils:: sugg:: Sugg ;
7- use clippy_utils:: { is_diag_trait_item , is_in_test, last_path_segment, local_is_initialized, sym} ;
7+ use clippy_utils:: { is_in_test, last_path_segment, local_is_initialized, sym} ;
88use rustc_errors:: Applicability ;
99use rustc_hir:: { self as hir, Expr , ExprKind } ;
1010use rustc_lint:: { LateContext , LateLintPass } ;
@@ -69,32 +69,32 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
6969 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' _ > ) {
7070 if let ExprKind :: Assign ( lhs, rhs, _) = e. kind
7171 && let typeck = cx. typeck_results ( )
72- && let ( call_kind, fn_name, fn_id , fn_arg, fn_gen_args) = match rhs. kind {
72+ && let ( call_kind, fn_name, fn_def , fn_arg, fn_gen_args) = match rhs. kind {
7373 ExprKind :: Call ( f, [ arg] )
7474 if let ExprKind :: Path ( fn_path) = & f. kind
75- && let Some ( id ) = typeck. qpath_res ( fn_path, f. hir_id ) . opt_def_id ( ) =>
75+ && let Some ( def ) = typeck. qpath_res ( fn_path, f. hir_id ) . opt_def ( cx ) =>
7676 {
77- ( CallKind :: Ufcs , last_path_segment ( fn_path) . ident . name , id , arg, typeck. node_args ( f. hir_id ) )
77+ ( CallKind :: Ufcs , last_path_segment ( fn_path) . ident . name , def , arg, typeck. node_args ( f. hir_id ) )
7878 } ,
79- ExprKind :: MethodCall ( name, recv, [ ] , _) if let Some ( id ) = typeck. type_dependent_def_id ( rhs. hir_id ) => {
80- ( CallKind :: Method , name. ident . name , id , recv, typeck. node_args ( rhs. hir_id ) )
79+ ExprKind :: MethodCall ( name, recv, [ ] , _) if let Some ( def ) = typeck. type_dependent_def ( rhs. hir_id ) => {
80+ ( CallKind :: Method , name. ident . name , def , recv, typeck. node_args ( rhs. hir_id ) )
8181 } ,
8282 _ => return ,
8383 }
8484 && let ctxt = e. span . ctxt ( )
8585 // Don't lint in macros.
8686 && ctxt. is_root ( )
8787 && let which_trait = match fn_name {
88- sym:: clone if is_diag_trait_item ( cx, fn_id , sym:: Clone ) => CloneTrait :: Clone ,
88+ sym:: clone if fn_def . assoc_fn_parent ( cx) . is_diag_item ( cx , sym:: Clone ) => CloneTrait :: Clone ,
8989 sym:: to_owned
90- if is_diag_trait_item ( cx, fn_id , sym:: ToOwned )
90+ if fn_def . assoc_fn_parent ( cx) . is_diag_item ( cx , sym:: ToOwned )
9191 && self . msrv . meets ( cx, msrvs:: CLONE_INTO ) =>
9292 {
9393 CloneTrait :: ToOwned
9494 } ,
9595 _ => return ,
9696 }
97- && let Ok ( Some ( resolved_fn) ) = Instance :: try_resolve ( cx. tcx , cx. typing_env ( ) , fn_id , fn_gen_args)
97+ && let Ok ( Some ( resolved_fn) ) = Instance :: try_resolve ( cx. tcx , cx. typing_env ( ) , fn_def . 1 , fn_gen_args)
9898 // TODO: This check currently bails if the local variable has no initializer.
9999 // That is overly conservative - the lint should fire even if there was no initializer,
100100 // but the variable has been initialized before `lhs` was evaluated.
0 commit comments