@@ -10,7 +10,7 @@ use rustc_middle::ty::{self, Instance, Mutability};
1010use rustc_session:: impl_lint_pass;
1111use rustc_span:: def_id:: DefId ;
1212use rustc_span:: symbol:: sym;
13- use rustc_span:: ExpnKind ;
13+ use rustc_span:: { ExpnKind , SyntaxContext } ;
1414
1515declare_clippy_lint ! {
1616 /// ### What it does
@@ -68,7 +68,8 @@ impl_lint_pass!(AssigningClones => [ASSIGNING_CLONES]);
6868impl < ' tcx > LateLintPass < ' tcx > for AssigningClones {
6969 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , assign_expr : & ' tcx Expr < ' _ > ) {
7070 // Do not fire the lint in macros
71- let expn_data = assign_expr. span ( ) . ctxt ( ) . outer_expn_data ( ) ;
71+ let ctxt = assign_expr. span ( ) . ctxt ( ) ;
72+ let expn_data = ctxt. outer_expn_data ( ) ;
7273 match expn_data. kind {
7374 ExpnKind :: AstPass ( _) | ExpnKind :: Desugaring ( _) | ExpnKind :: Macro ( ..) => return ,
7475 ExpnKind :: Root => { } ,
@@ -83,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
8384 } ;
8485
8586 if is_ok_to_suggest ( cx, lhs, & call, & self . msrv ) {
86- suggest ( cx, assign_expr, lhs, & call) ;
87+ suggest ( cx, ctxt , assign_expr, lhs, & call) ;
8788 }
8889 }
8990
@@ -221,14 +222,20 @@ fn is_ok_to_suggest<'tcx>(cx: &LateContext<'tcx>, lhs: &Expr<'tcx>, call: &CallC
221222 implemented_fns. contains_key ( & provided_fn. def_id )
222223}
223224
224- fn suggest < ' tcx > ( cx : & LateContext < ' tcx > , assign_expr : & Expr < ' tcx > , lhs : & Expr < ' tcx > , call : & CallCandidate < ' tcx > ) {
225+ fn suggest < ' tcx > (
226+ cx : & LateContext < ' tcx > ,
227+ ctxt : SyntaxContext ,
228+ assign_expr : & Expr < ' tcx > ,
229+ lhs : & Expr < ' tcx > ,
230+ call : & CallCandidate < ' tcx > ,
231+ ) {
225232 span_lint_and_then ( cx, ASSIGNING_CLONES , assign_expr. span , call. message ( ) , |diag| {
226233 let mut applicability = Applicability :: Unspecified ;
227234
228235 diag. span_suggestion (
229236 assign_expr. span ,
230237 call. suggestion_msg ( ) ,
231- call. suggested_replacement ( cx, lhs, & mut applicability) ,
238+ call. suggested_replacement ( cx, ctxt , lhs, & mut applicability) ,
232239 applicability,
233240 ) ;
234241 } ) ;
@@ -274,6 +281,7 @@ impl<'tcx> CallCandidate<'tcx> {
274281 fn suggested_replacement (
275282 & self ,
276283 cx : & LateContext < ' tcx > ,
284+ ctxt : SyntaxContext ,
277285 lhs : & Expr < ' tcx > ,
278286 applicability : & mut Applicability ,
279287 ) -> String {
@@ -293,7 +301,7 @@ impl<'tcx> CallCandidate<'tcx> {
293301 // Determine whether we need to reference the argument to clone_from().
294302 let clone_receiver_type = cx. typeck_results ( ) . expr_ty ( receiver) ;
295303 let clone_receiver_adj_type = cx. typeck_results ( ) . expr_ty_adjusted ( receiver) ;
296- let mut arg_sugg = Sugg :: hir_with_applicability ( cx, receiver, "_" , applicability) ;
304+ let mut arg_sugg = Sugg :: hir_with_context ( cx, receiver, ctxt , "_" , applicability) ;
297305 if clone_receiver_type != clone_receiver_adj_type {
298306 // The receiver may have been a value type, so we need to add an `&` to
299307 // be sure the argument to clone_from will be a reference.
@@ -311,7 +319,7 @@ impl<'tcx> CallCandidate<'tcx> {
311319 Sugg :: hir_with_applicability ( cx, lhs, "_" , applicability) . mut_addr ( )
312320 } ;
313321 // The RHS had to be exactly correct before the call, there is no auto-deref for function calls.
314- let rhs_sugg = Sugg :: hir_with_applicability ( cx, self_arg, "_" , applicability) ;
322+ let rhs_sugg = Sugg :: hir_with_context ( cx, self_arg, ctxt , "_" , applicability) ;
315323
316324 format ! ( "Clone::clone_from({self_sugg}, {rhs_sugg})" )
317325 } ,
@@ -340,11 +348,11 @@ impl<'tcx> CallCandidate<'tcx> {
340348
341349 match self . kind {
342350 CallKind :: MethodCall { receiver } => {
343- let receiver_sugg = Sugg :: hir_with_applicability ( cx, receiver, "_" , applicability) ;
351+ let receiver_sugg = Sugg :: hir_with_context ( cx, receiver, ctxt , "_" , applicability) ;
344352 format ! ( "{receiver_sugg}.clone_into({rhs_sugg})" )
345353 } ,
346354 CallKind :: FunctionCall { self_arg, .. } => {
347- let self_sugg = Sugg :: hir_with_applicability ( cx, self_arg, "_" , applicability) ;
355+ let self_sugg = Sugg :: hir_with_context ( cx, self_arg, ctxt , "_" , applicability) ;
348356 format ! ( "ToOwned::clone_into({self_sugg}, {rhs_sugg})" )
349357 } ,
350358 }
0 commit comments