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
Copy field bindings copy while Copy element bindings view — §3.8 says the rule is uniform #1531
Question for a ruling (spec text vs. implementation; not changed by #1408).
§3.8: "A binding names what's there; an annotation demands what it says: an unannotated let binds the view unchanged, while a typed binding is an owned-value demand (D22 §6.2, D27). This is uniform across field projections and collection element access." D27 ruling 3 says the same.
For a Copy element the implementation binds a view; for a Copy field it binds a copy:
fn main:
var v: Vec[i32] = Vec.new()
v.push(1)
let x = v[0]
v[0] = 9 // error: cannot mutate `v` while `x` is a live view into it
print(x)
type S { n: i32 }
fn main:
var s = S { n: 1 }
let x = s.n
s.n = 5 // accepted
print(x) // prints 1
(stage1 of origin/main ba2d5d1). Joins follow the same split: if c: v[0] else: v[1] is &i32; if c: s.n else: s.m is i32. #1408 makes a join of non-Copy field places a view (the alternative there was the D32 rejection) and deliberately leaves Copy field joins as values, matching the plain Copy field binding.
The question: is the Copy field binding (and join) non-compliant with "uniform across field projections and collection element access" — should let x = s.n view s.n like let x = v[0] views v[0], with the let x: i32 = ... spelling for the copy — or is a Copy field read meant to stay a value?
Activity
Sema/MIR: a join whose arms are all non-Copy field places is a view o…
Sema/MIR: a join whose arms are all non-Copy field places is a view o…
Spec v7.6 (D74): entry sources vs module files; optional-chain field …
build/compiler.w: the stack-report Copy field takes its explicit type…
Sema: an unannotated `let` of a Copy field binds a view, as a Copy el…
build/compiler.w: the stack-report Copy field takes its explicit type…
build/compiler.w: the stack-report Copy field takes its explicit type…
docs/ in csharplang's shape: spec/ per chapter, meetings/ per ruling,…
Type checker: D74 entry sources and chain moves, field-view bindings (w…
test: the #1531 copy-field view fixture gives way to D144
D144: a binding from a place of plain bits takes the value, any other…