Skip to content

for cannot iterate an iterator adapter: §13.5's for (i, item) in collection.enumerate() does not compile #2152

Closed

Description

@ehartford

Spec: §13.5 shows for (i, item) in collection.enumerate():; §13.1: "for loops, .zip(), .peekable(), .windows() — all work as you'd expect"; §13.6 uses [w.clone(): i for (i, w) in vocab.enumerate()].

Today (v0.15.3.0, main 3f1aa3d), with let xs: Vec[i32] = [1, 2, 3]:

Loop Result
for (i, x) in xs.enumerate(): … unknown method 'enumerate' for type 'Vec[i32]'
for (i, x) in xs.iter().enumerate(): … cannot iterate over `EnumerateIter[VecIter[i32], i32]`: a `for` iterable implements `Iter[T]` …
for x in xs.iter() |> filter(it > 1): … same refusal, FilterIter[VecIter[i32], i32]
for x in xs.iter() |> map(it * 2): … same, MapIter[…]
for (a, b) in xs.iter() |> zip(xs.iter()): … same, ZipIter[…]
[(i, w.len()) for (i, w) in names.enumerate()] refused at names.enumerate()

The adapters work as pipeline stages feeding count/sum/collect, but none is a for iterable, and enumerate is not a method of a collection.

Also: for i, x in xs: print(x) (two names, no parentheses) parses, binds something as an index, and then fails in MIR lowering ([mir-var-miss] sym=x), an internal error for a spelling the spec does not have; it should be a parse error or the indexed loop.

Expected: every adapter is a for iterable (it has a next()), collection.enumerate() exists, and the comprehension form follows.

Activity

  1. ehartford commented on Oct 5, 2026

    @ehartford
    ContributorAuthor

    Fixed on main baa84b2 (#2150); battery green on the stack.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions