@@ -116,18 +116,18 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
116116 continue ;
117117 }
118118
119- // `{ arg = &cloned; clone(move arg); }` or `{ arg = &cloned; to_path_buf(arg); }`
120- let Some ( ( cloned, cannot_move_out) ) = find_stmt_assigns_to ( cx, mir, arg, from_borrow, bb) else {
121- continue ;
122- } ;
123-
124119 let loc = mir:: Location {
125120 block : bb,
126121 statement_index : bbdata. statements . len ( ) ,
127122 } ;
128123
129124 // `Local` to be cloned, and a local of `clone` call's destination
130125 let ( local, ret_local) = if from_borrow {
126+ // `{ arg = &cloned; clone(move arg); }` or `{ arg = &cloned; to_path_buf(arg); }`
127+ let Some ( ( cloned, cannot_move_out) ) = find_stmt_assigns_to ( cx, mir, arg, from_borrow, bb) else {
128+ continue ;
129+ } ;
130+
131131 // `res = clone(arg)` can be turned into `res = move arg;`
132132 // if `arg` is the only borrow of `cloned` at this point.
133133
@@ -149,7 +149,6 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
149149 // receiver of the `deref()` call
150150 let ( pred_arg, deref_clone_ret) = if let Some ( ( pred_fn_def_id, pred_arg, pred_arg_ty, res) ) =
151151 is_call_with_ref_arg ( cx, mir, & pred_terminator. kind )
152- && res == cloned
153152 && cx. tcx . is_diagnostic_item ( sym:: deref_method, pred_fn_def_id)
154153 && let ty:: Adt ( pred_arg_def, _) = pred_arg_ty. kind ( )
155154 && let Some ( pred_arg_name) = cx. tcx . get_diagnostic_name ( pred_arg_def. did ( ) )
@@ -178,7 +177,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
178177 // StorageDead(pred_arg);
179178 // res = to_path_buf(cloned);
180179 // ```
181- if cannot_move_out || !possible_borrower. only_borrowers ( & [ arg, cloned ] , local, loc) {
180+ if cannot_move_out || !possible_borrower. only_borrowers ( & [ arg, deref_clone_ret ] , local, loc) {
182181 continue ;
183182 }
184183
0 commit comments