I think one of the priority documentation item is borrow scopes, i.e. how long something is considered to be borrowed. All examples in ownership chapter of TRPL are let bindings.
The following issue is relevant, and I think the issue should get higher priority than P-low.
Here is my understanding of current rules:
- Things are borrowed for the innermost enclosing statement.
- let bindings are borrowed for the innermost enclosing block.
- Tail expression of block is special and is borrowed for the innermost enclosing block of block, not expression. This rule is recursive.
- Implication of 1 is that something borrowed in true branch of if expression is also borrowed in false branch, likewise for different arms of match expression. This will be fixed.
- Implication of 2 is that
let x = y; xis not equivalent to
yand you may need to introduce or eliminate let bindings to pass the borrow checker. Will this be fixed?
- Another implication of 2 is that destructuring let is not equivalent to destructuring match, because match bindings are borrowed for the innermost enclosing statement, not block. This is probably working as designed, as long as we have rule 2.
- Another implication of 1 and 2 is that since things are not borrowed for something less than a statement,
xis borrowed until
f(g(&x)), not until
greturns. So you may need to introduce or eliminate temporaries to pass the borrow checker. Will this be fixed?