ADR-387: A View of a Type That Copies Is Copied Where the Value Is Wanted

Status: Accepted (#1107) Date: November 1, 2026 (architect’s decision under the owner’s rule of 2026-10-31, docs/supervisor.md, Language decisions: the form the language already has for a call, said for every place that wants the value) Answers: b26’s Needs: architect decision (#1107, rows 4-5): let e: ref C = xs[0]; let g: C = e is NK1103 for a struct C that copies, and so is let f: ref i64 = ys[0]; let h: i64 = f, though a call slow(f) into slow(x: i64) is accepted Related: ADR-233 D4 (a view of a value that copies goes where the value is wanted, at a call), ADR-279 D8 (at a read, a word is copied and every other type lent) and D9 (a copy type handed on whole is not taken), ADR-283 D3 (no copy is inserted of a value that does not copy), ADR-views-3 (an element read is a view)

1. Question

ADR-233 D4 lets a ref i64 go where an i64 is wanted, at a call, by a name. A let that declares the value’s type, a return into a function whose result is the value, a field of a struct being built and a push are refused (NK1103, NK1104), for a number and for a struct that copies alike. Since #1107 a list or map element unwrapped by ?? or a match stays a view, so this refusal now meets every program that reads a copy struct out of a map and keeps it. Is a view of a type that copies copied where the value is wanted?

2. Decision

D1 - Every place that wants the value takes a copy of the view

Where a value of a type that copies is wanted - a let or let mut that declares the type, an argument to a parameter of that type, a return into a result of that type, a field of a struct or a variant being built, an element handed to push, insert or a list literal - a view of it (ref T) is accepted and copied. A type that copies is one of ADR-279 D8’s words, or a struct, tuple, array or enum the ledger says copies. The emitter writes the * (or nothing, where Rust copies by itself).

D2 - What stays as it was

A view of a type that does not copy is still refused there (NK1103/ NK1104, help .clone(); ADR-283 D3). A let with no type over a view keeps the view (ADR-279 D8, ADR-views-3): the copy is made only where the program wrote or declared the value’s type. NK2105/NK2106 stay silent (ADR-279 D9).

3. Why (the principles)

This site is open source. Improve this page.