Open and answer this issue on GitHub.
ready · opened 2026-11-03 · updated 2026-11-03 · 0 comments
(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”).
xs while the result holds a view of it, so the buffer moves into the result’s keep (D9, D10’s last sentence, ADR-283 D23). No copy is made and no error is raised. The brief that ordered a refusal was wrong.tethered in the ledger, as text is. A struct literal lends; building it is not keeping (D5, last paragraph). NK2105 here is a defect.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/.make probe, plus a version where xs is large, with no .clone() in the emitted code (check with --emit).Part of #1213.