Skip to content

An iterator over a collection literal bound to a variable reads a dead temporary: var d = [1, 2] |> map(x => x * 2); d.next() is None #3004

Closed

Description

@ehartford

Found while writing the §13.3 fixtures (#2943). Installed compiler (main ecbc23b):

var doubled = [1, 2] |> map(x => x * 2)
print(doubled.next().unwrap())
panic: called unwrap on None

[1, 2] |> peekable() the same. The pipeline inserts .iter() on the literal (D142), the ListIter views the temporary, and the temporary dies at the end of the statement (§21.1); the adapter bound to doubled then steps a dead list and answers None. Binding the list first (let two = [1, 2]; var d = two |> map(…)) works.

Three-way: the compiler is wrong. §21.1 rule 1 says a view that cannot outlive its statement is refused or, for a literal, the temporary lives as long as the binding (D174 establishes an owned-value demand for an unannotated binding of such a view). Expected: either the literal is materialized as a binding-lifetime temporary, or the statement is refused with the §21.1 message, never a silently empty iterator. A for over the same pipeline (for x in [1, 2] |> map(…)) is fine because the loop consumes it in the statement.

Activity

  1. added
    spec-gap
    on Nov 3, 2026
  2. added a commit that references this issue on Nov 5, 2026
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

    spec-gap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions