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
D69: the body of for x in g may mutate a place the generator views (aliasing accepted) #1734
Spec: §13.4 (D69 push generators), §21.1 (views), §2 (exactly as safe as Rust).
The body of for x in g may mutate a place the generator value views. Sema rejects the mutation between creating the generator and the loop (cannot mutate lines while g is a live view into it), but not inside the loop body, which runs while the generator is iterating that very place:
gen fn each_line(lines: &Vec[str]) -> &str:
for line in lines:
yield line
fn main:
var lines: Vec[str] = ["a".clone(), "b".clone()]
var n = 0
for l in each_line(&lines):
n += 1
if n < 40:
lines.push(f"line {n}") // accepted; the producer's loop still walks the old buffer
print(n)
with check says ok (gen-push-impl, and gen-push-fixes). The equivalent over a Vec is rejected: for p in ps: ps.push(...) → "cannot mutate ps while p is a live view into it". The same hole applies to a generator method's borrowed receiver (#1724: for x in c.walk(): c.items.push(..)).
Expected: the generator value's view dependencies (record_generator_call_ref_origins) are live borrows for the whole loop, as the implicit .iter() borrow of a for over a collection is; a mutation of a viewed place in the body is a compile error.
Activity
D69: a generator's views are live for the whole loop over it — the bo…
D69: a generator's views are live for the whole loop over it — the bo…
D69: a generator's views are live for the whole loop over it — the bo…
D69: a generator's views are live for the whole loop over it — the bo…
D69: a generator's views are live for the whole loop over it — the bo…
D69 follow-ups: generic and method gen fn, comprehensions and goto ov…