cli: implement explicit source borrow returns

This commit is contained in:
dev committed 2026-10-07 18:20:45 +03:00
1 parent 715a8be491
commit a9a0d63f27
78 files changed
+970 -48

No files matched your search

+8 -1
View File
@@ -101,11 +101,18 @@ Rules (checked by the verifier):
- **A borrow lives until the end of the block where it was bound** (`ref r = …;` / `mut r = …;`). A borrow written as an argument (`f(mut buf)`) lives for that call. To end one early, put it in an inner `{ … }` block.
- **Exclusive XOR shared.** While a `mut` borrow of a place is live, no other borrow of the same place, and no direct use of it, is allowed (`E2101`). Disjoint fields and `split_at` halves are independent.
- A borrow cannot outlive what it borrows from (`E2102`). A function returns a borrow only with `-> ref<T> from param`.
- A borrow cannot outlive what it borrows from (`E2102`). A function returns a borrow only with explicit `from param`. Bind returned views with `ref`/`mut`; the `from` argument must be a named borrow. Return the bound name without `move`; a local-frame view cannot escape (`E2108`).
- **Moves are explicit:** a named linear value is consumed only as `move x` (otherwise `E7003`). A fresh temporary needs no `move`: `consume(make())`. Copyable values are passed plainly; `move` on them is `E7006`.
- Use after move is `E2001`, use after close/free/take `E3001`, a second consumption `E2002`, and a linear value never consumed `E3002`. Every path must consume it, including early `return`s.
- Index proofs: inside `if i < s.len { … }` the access `s[i]` needs no runtime check.
Returned views (details in `/docs/language/ownership.md`):
```aji
fn first(s: slice<u64>) -> ref<u64> from s effects [] { ref item = s[0]; return item; }
fn main() -> u64 effects [] { let data = [42u64, 7u64]; ref s = data; ref item = first(s); return *item; }
```
## 5. Failure: every outcome is a `match` arm
```aji