Skip to content

Commit 28cfbd4

Browse files
committed
analyze: last_use: comment explaining last-use in terms of liveness
1 parent ab616f3 commit 28cfbd4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

c2rust-analyze/src/last_use.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
//! Analysis to find the last use of a MIR local. For non-`Copy` types, the last use can be made
22
//! into a move instead of a clone or borrow.
33
//!
4+
//! In terms of liveness analysis, a "last use" is a statement where a variable transitions from
5+
//! live to dead as a result of its use in the statement. A variable can also become dead due to
6+
//! control flow: in `if f(p) { g(p); }`, the variable `p` is still live after evaluating `f(p)`,
7+
//! but becomes dead upon taking the `else` branch, which contains no more uses of `p`. In this
8+
//! example, `g(p)` is a last use, but `f(p)` is not (and in the `else` case, no last use of `p`
9+
//! will be encountered during execution).
10+
//!
411
//! We specifically use this when handling borrows of non-`Copy` pointers like `Option<&mut T>`.
512
//! At most use sites, we produce `ptr.as_deref_mut().unwrap() ...`, which borrows `ptr` instead of
613
//! moving it. However, this construction produces a reference with a shorter lifetime, matching

0 commit comments

Comments
 (0)