diag: guide parameter mutability and explicit array slice arguments

This commit is contained in:
dev committed 2026-10-09 21:12:26 +03:00
1 parent 6a02659f31
commit 9549a3dec6
22 files changed
+197 -4

No files matched your search

+2
View File
@@ -12,6 +12,7 @@ Aji makes every significant action explicit — moves, borrows, allocation, clos
| a narrowing `x as T` | `x as! T` checks/traps; `x as% T` wraps |
| `let mut x = value` / `var x = value` | `var x: T = value;` (type required) |
| immutable `let x = value` | `let x = value;` (type may be inferred) |
| `fn f(mut x: T)` | `fn f(x: T)` with a local `var`, or `fn f(x: mut<T>)` for an exclusive borrow; choose the ownership contract |
| mutable/shared slice type | `slice_mut<T>` / `slice<T>` |
| `s[start..]` | `s[start..end]` (explicit upper bound) |
| `f(&x)` / `f(&mut x)` | `f(ref x)` / `f(mut x)` |
@@ -118,6 +119,7 @@ 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.
- A whole-array argument `f(ref a)` / `f(mut a)` preserves the array for a `ref<[T; N]>` / `mut<[T; N]>` parameter; otherwise it becomes a slice. Length and mode must match. Bound array borrows remain slices.
- An array value is not a slice argument: use `f(ref a)` for `slice<T>` or `f(mut a)` for `slice_mut<T>`; the place and loan must verify.
- **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 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`.