OxL Reference

error borrow-escape

error Standard: [§7.2]

What it means#

There are no explicit lifetimes: borrow types (&T, &var T, [T], view T) MUST NOT be stored in fields of data, enum or actors, captured by escaping closures, sent to another task, or appear in Task and stream types. A borrow also must not outlive the borrowed value, and a function may return a borrow only if it comes from self or from the only borrowed parameter (§7.2).

Example#

oxl✓ checked in CI
data Holder {
  items: &List<i32>      // <- borrow-escape
}
error
borrow-escape

How to fix#

oxl✓ checked in CI
data Holder {
  items: List<i32>
}

Store an owned value (move it in, or .clone() it), or share through Arc<frozen T> when several owners are needed.

Zero-copy views (view T, §9.6)#

decode_view<T>(&buf) returns a view T that borrows buf: it follows the same rules. Returning a view of a local buffer is the usual mistake:

oxl
fn parse() -> view Order {
  let buf = receive()
  decode_view<Order>(&buf)!   // <- borrow-escape: `buf` does not outlive the function
}

Take the buffer as a borrowed parameter (fn parse(buf: &bytes) -> view Order), or return an owned value with v.own() (fn parse() -> Order). A view T also cannot be stored in a field, captured by an escaping closure or sent to another task; an rpc parameter rpc f(o: view T) is the exception, the runtime keeps its buffer alive for the handler (D-6504..D-6506).

See also#

OxL 1.0.0-beta · Documentation version 1.0.0-beta© OxwaldLink · generated from the Standard, the std sources and the guides