You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Returned-origin tracking pins a field view to the loop/element binding instead of the borrowed parameter it came from #1297
Found rewriting `examples/json-parser` under #1150 ruling 4 (`json_get_field(val: &JsonValue, key) -> Option[&JsonValue]`).
D22/D27: a view projected out of a borrowed parameter has that parameter's origin, and a function may return it. The checker instead pins a field projection of a loop binding (or of `xs[i]` / `xs.get(i)`) to that binding and rejects the return:
```
enum JV { Null | Str(str) | Object(Vec[KV]) }
type KV { key: str, value: JV }
fn get(val: &JV, key: str) -> Option[&JV]:
match val:
.Object(entries) =>
for entry in entries:
if entry.key == key:
return Some(&entry.value) // error: returned ephemeral value may outlive its origin 'entry'
None
_ => None
```
The same for `return Some(&entries[i].value)` ("origin 'entries'") and `let entry = entries.get(i); return Some(&entry.value)`, and for the method form (`extend JV: fn get(key)` on `self`). Returning the element itself works (`return Some(entries.get(i))`, `Some(items.get(i))` for an array), so the missing piece is the field projection step: `&entry.value` should inherit `entry`'s origin, which is `val`.
Activity
examples: rewritten to the current spec (D55 ruling 4) + examples-tes…
Sema: a field view of a borrowed collection element keeps its origin …
examples: restore the spec spellings #1308 parked behind now-fixed co…