Rules for the Creation of Borrows
Mutable Borrows
Consider the stmt p = &mut q, at a program point , where has type , and has type , and is a type containing lifetimes .
At the end of the PreOperands phase, the PCG is guaranteed to be in a state where, for each the lifetime projection is in the graph. During the Operands phase, each lifetime projection is labelled with the current program point to become . At the end of the PreMain phase, for each , the lifetime projection is guaranteed not to be in the graph. During the Main phase, these projections are added.
Subsequently, the labelled lifetime projections under are connected with BorrowFlow edges to the new lifetime projections under . Namely, for each if outlives , then a BorrowFlow edge is added.
Subsequently, we introduce Future nodes and edges to account for nested references as follows. For each :
- Insert the node into the graph
- If any
Futureedges originate from the labelled projection , redirect them such that they originate from . - Insert a
Futureedge - Insert a
Futureedge