OxL Reference

7.2 Borrows

  • &x creates a shared borrow, &var x an exclusive one. While &var x exists, there are no other borrows of x and no access to x; while &x exist, x cannot be modified.
  • A borrow cannot outlive the borrowed value.
  • No explicit lifetimes. Borrow types (&T, &var T, [T], view T) MUST NOT: be stored in the fields of data, enum, actors; be captured by escaping closures; be passed to another task; be part of a Task/stream.
  • A function MAY return a borrow only if it is derived from self or from the only borrow parameter.

Implementation-defined. Precision of borrow checking (D-8051; DIV-002; D-600). The Standard does not introduce lifetimes and does not prescribe an algorithm. Every accepted program MUST satisfy the rules above; an implementation MAY reject programs whose safety it cannot prove. This implementation uses lexical borrows: a borrow lives until the last statement of the block that mentions the reference, not until the end of the block; for fields the rule is path-sensitive (&var t.a does not block t.b).

borrow-conflict, borrow-escape

See also

Source: docs/spec/oxl-standard.en.md