mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-14 04:56:49 +00:00
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.
This commit is contained in:
parent
9de642190e
commit
a377378528
@ -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) ||
|
||||
|
Loading…
Reference in New Issue
Block a user