Skip to content

Commit fd9f5df

Browse files
committed
Add comment and rename
1 parent 22f396a commit fd9f5df

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

clippy_lints/src/redundant_clone.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ fn is_call_with_ref_arg<'tcx>(
250250

251251
type CannotMoveOut = bool;
252252

253-
/// Finds the first `to = (&)from`, and returns `Some(from)`.
253+
/// Finds the first `to = (&)from`, and returns
254+
/// ``Some((from, [`true` if `from` cannot be moved out]))``.
254255
fn find_stmt_assigns_to<'a, 'tcx: 'a>(
255256
cx: &LateContext<'_, 'tcx>,
256257
mir: &mir::Mir<'tcx>,
@@ -263,10 +264,10 @@ fn find_stmt_assigns_to<'a, 'tcx: 'a>(
263264
if *local == to {
264265
if by_ref {
265266
if let mir::Rvalue::Ref(_, _, ref place) = **v {
266-
return base_local(cx, mir, place);
267+
return base_local_and_movability(cx, mir, place);
267268
}
268269
} else if let mir::Rvalue::Use(mir::Operand::Copy(ref place)) = **v {
269-
return base_local(cx, mir, place);
270+
return base_local_and_movability(cx, mir, place);
270271
}
271272
}
272273
}
@@ -275,15 +276,20 @@ fn find_stmt_assigns_to<'a, 'tcx: 'a>(
275276
})
276277
}
277278

278-
fn base_local<'tcx>(
279+
/// Extracts and returns the undermost base `Local` of given `place`. Returns `place` itself
280+
/// if it is already a `Local`.
281+
///
282+
/// Also reports whether given `place` cannot be moved out.
283+
fn base_local_and_movability<'tcx>(
279284
cx: &LateContext<'_, 'tcx>,
280285
mir: &mir::Mir<'tcx>,
281286
mut place: &mir::Place<'tcx>,
282287
) -> Option<(mir::Local, CannotMoveOut)> {
283288
use rustc::mir::Place::*;
284289

290+
// Dereference. You cannot move things out from a borrowed value.
285291
let mut deref = false;
286-
// Accessing a field of an ADT that has `Drop`
292+
// Accessing a field of an ADT that has `Drop`. Moving the field out will cause E0509.
287293
let mut field = false;
288294

289295
loop {

0 commit comments

Comments
 (0)