Skip to content

An explicit move of a field while a view of it is live is accepted; the view reads the blank #1530

Closed

Description

@ehartford

Spec: §2.2 (D32) — "An explicit move place.field … a vacate is a write"; §21.1 / §3.8 — a view's origin may not be written while the view is live; §3.8 "A binding names what's there … an unannotated let binds the view unchanged … uniform across field projections and collection element access."

type S { s: str, n: i32 }
fn main:
    var x = S { s: "x" ++ "y", n: 1 }
    let p = x.s
    let q = move x.s
    print(p)
    print(q)

Actual (stage1 of origin/main ba2d5d1): compiles; prints an empty line, then xy. p is a view of x.s (MIR binds it as an alias place), the explicit vacate blanks x.s (reset-on-move) while p is still used, and p reads the blank. Memory-safe by the blank, wrong by the spec.

The same vacate under an element view is rejected (let e = v[0] then v.remove(0) while e is live), and an assignment x.s = "z".clone() under the same field view is rejected ("cannot mutate x while p is a live view into it").

Expected: move x.s while a view of x.s (or of x) is live is the same view-invalidation error as the assignment.

Found while building the #1408 field-join matrix (the view join inherits the hole: let p = if c: x.s else: y.s; let q = move x.s; print(p)).

Activity

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