@@ -250,7 +250,8 @@ fn is_call_with_ref_arg<'tcx>(
250
250
251
251
type CannotMoveOut = bool ;
252
252
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]))``.
254
255
fn find_stmt_assigns_to < ' a , ' tcx : ' a > (
255
256
cx : & LateContext < ' _ , ' tcx > ,
256
257
mir : & mir:: Mir < ' tcx > ,
@@ -263,10 +264,10 @@ fn find_stmt_assigns_to<'a, 'tcx: 'a>(
263
264
if * local == to {
264
265
if by_ref {
265
266
if let mir:: Rvalue :: Ref ( _, _, ref place) = * * v {
266
- return base_local ( cx, mir, place) ;
267
+ return base_local_and_movability ( cx, mir, place) ;
267
268
}
268
269
} 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) ;
270
271
}
271
272
}
272
273
}
@@ -275,15 +276,20 @@ fn find_stmt_assigns_to<'a, 'tcx: 'a>(
275
276
} )
276
277
}
277
278
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 > (
279
284
cx : & LateContext < ' _ , ' tcx > ,
280
285
mir : & mir:: Mir < ' tcx > ,
281
286
mut place : & mir:: Place < ' tcx > ,
282
287
) -> Option < ( mir:: Local , CannotMoveOut ) > {
283
288
use rustc:: mir:: Place :: * ;
284
289
290
+ // Dereference. You cannot move things out from a borrowed value.
285
291
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.
287
293
let mut field = false ;
288
294
289
295
loop {
0 commit comments