Issue #1218: Views-3: a struct field fed from a view of a local or a lent parameter reaches rustc or is refused as keeping

Open and answer this issue on GitHub.

ready · opened 2026-11-03 · updated 2026-11-03 · 0 comments

Probes (develop, after v2 of the views-3 lane)

(a) A view of a local handed back inside a struct reaches rustc (“Cannot return value referencing local variable”):

struct L { n: i64 }
struct W { own: ref L, k: i64 }
fn make() -> W { let xs = [L { n: 3 }]; let first: ref L = xs[0]; return W { own: first, k: 1 } }

The same in the views-3 spelling reaches rustc too (“Mismatched types”):

struct L { n: i64, tag: String }
struct W { own: L, k: i64 }
fn make() -> W { let xs = [L { n: 3, tag: "a" }]; let first = xs[0]; return W { own: first, k: 1 } }

(b) A lent parameter put in a struct literal is reported as kept: fn go(l: L) -> i64 { let w = W { own: l, k: 1 }; return show(w) } gives NK2105 at the caller (“go keeps l”).

Decision (supervisor, 2026-11-03; it follows from ADR-views-3)

To build

  1. Building on text’s tether representation, a field of a non-text type that receives a view (xs[0], config.part, a lent parameter) is emitted as tethered. A field that receives an owned value (a call result or a literal) owns it. The ledger lists the field under tethered. The make probes compile and print their values; go is accepted, with no NK2105. Tests in tests/compiler/.
  2. A struct holding a view of a local is returned with the buffer moved into its keep (anchored, D9/D23), with no copy. Test: the make probe, plus a version where xs is large, with no .clone() in the emitted code (check with --emit).

Part of #1213.

Back to Open Issues