Skip to content

v.iter() over elements that own something yields views; every iterator adapter is a for iterable (#2145, #2152) - #2150

Merged
ehartford merged 1 commit into
std-clone-option-resultfrom
fix-2145
Oct 5, 2026
Merged

ehartford merged 1 commit into
std-clone-option-resultfrom
fix-2145

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

names.iter() on a Vec[str] (any element that is not Copy) resolves to the view iterator (VecIterRef[T], items &T), as §13.1 says a vector's iterator yields. The by-value VecIter[T] handed each element out as a byte copy with a second owner; every .iter() |> filter/map/collect, and .next(), double-freed. Sema records the resolved method (method_call_fields), so MirLower reads it and not the spelling.

A Copy element keeps the by-value iterator for now: switching it changes what collect and sum see (xs.iter_ref() |> sum() is invalid LLVM today), which is D22's contextual Copy reaching pipelines and its own change.

Test: test/debug_alloc/da_2145_vec_iter_views_owned_elements.w (filter, map, any, take, collect, clone-collect, next, for, an enum element), leak count 0, no double free.

Gaps seen on the way, same on main: for (i, x) in v.iter() |> enumerate() is refused; |> position(it == "a") and kept[0] == "a" on a Vec[&str] are "comparison operands must have compatible types".

@ehartford ehartford changed the title v.iter() over elements that own something yields views (#2145) v.iter() over elements that own something yields views; every iterator adapter is a for iterable (#2145, #2152) Oct 5, 2026
@ehartford
ehartford changed the base branch from main to std-clone-option-result October 5, 2026 12:23
@ehartford
ehartford added this pull request to stack #2167 October 5, 2026 12:23
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on the stack top cef3897, driven by the pinned seed (gate 759 s, uat 30 s, battery-checks 1361 s); green recorded with :last-green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant