Skip to content

IntoIter.iter() is declared mut fn; spec §13 requires iter() on borrowed receivers #716

Closed

Description

@ehartford

lib/std/collections.w declares:

pub trait IntoIter[T]:
    mut fn iter() -> VecIter[T]

so shared.iter() through &Vec is rejected (§15.2), and iter() while any
shared view lives is a view-conflict — but iter() only constructs a read-only
VecIter { data_ptr, len, idx } view. Spec §13's implicit-iteration rule shows
for item in my_vec.iter() as the explicit spelling of the borrowing form,
so expression-position iter() must work on borrowed/immutable receivers.

Changing the declarations to fn iter() alone breaks dispatch ("wrong
argument count" at call sites) — the builtin intercept/trait plumbing couples
to the mut receiver convention, so the fix needs the method-call path updated
together with the declarations. Tests currently spell around it
(issue64_borrowed_vec_methods iterates the owned var before creating views).

Activity

  1. ehartford commented on Jul 25, 2026

    @ehartford
    ContributorAuthor

    Eric ruling 2026-07-25: approved — fn iter() lands as §13.2 compliance ("the registered borrow on the receiver is shared") in its own isolated batch after the current batch's battery is recorded, per the receiver-mode blast-radius rule (alone, with :move-audit/:drop-audit). Work item: root-cause the trait-dispatch "wrong argument count" break that the direct receiver-mode flip exposed, then change the Vec impl, the IntoIter trait method, and the sibling collection iter() declarations together.

  2. ehartford commented on Jul 27, 2026

    @ehartford
    ContributorAuthor

    Resolved by evolution — verified on v0.15.1-geb0a0cf31. lib/std/collections.w now declares 'pub trait IntoIter[T]: fn iter(self: &Self) -> VecIter[T]' (shared receiver, not mut fn), and the spec §13 spellings all work: shared.iter() through a &Vec, 'for x in v.iter()', 'for y in ro.iter()' on an immutable binding, and IntoIter trait dispatch through a &C parameter. A neighbouring gap found while verifying — auto-ref not firing for a generic &C parameter, plus a misreported expected type in that diagnostic — is filed as #737.

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