Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Only fires on temporaries
`let y = x.clone()` cannot be turned into `let y = x` without moving x,
regardless of whether `y` is consumed or not.
  • Loading branch information
sinkuu committed Mar 12, 2020
1 parent 9de6421 commit a377378
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions clippy_lints/src/redundant_clone.rs
Expand Up @@ -192,10 +192,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
(local, deref_clone_ret)
};

// 1. `local` cannot be moved out if it is used later.
// 2. If `ret_local` is not consumed, we can remove this `clone` call anyway.
let is_temp = mir_read_only.local_kind(ret_local) == mir::LocalKind::Temp;

// 1. `local` can be moved out if it is not used later.
// 2. If `ret_local` is a temporary and is not consumed, we can remove this `clone` call anyway.
let (used, consumed) = traversal::ReversePostorder::new(&mir, bb).skip(1).fold(
(false, false),
(false, !is_temp),
|(used, consumed), (tbb, tdata)| {
// Short-circuit
if (used && consumed) ||
Expand Down

0 comments on commit a377378

Please sign in to comment.