7.2 Borrows
&xcreates a shared borrow,&var xan exclusive one. While&var xexists, there are no other borrows ofxand no access tox; while&xexist,xcannot 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 ofdata,enum, actors; be captured by escaping closures; be passed to another task; be part of aTask/stream. - A function MAY return a borrow only if it is derived from
selfor 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.adoes not blockt.b).
Related diagnostics
borrow-conflict, borrow-escape
See also
Source: docs/spec/oxl-standard.en.md