Skip to content

An enum of values is not Copy (D120 stage 3 left enums opt-in), so D144 makes match g on a bare local need move g #2549

Closed

Description

@ehartford

Ceremony report (D144 fallout). An enum whose every payload is a value is not Copy unless impl Copy is written, so under D144 a match on a bare local observes it and a consuming use of the payload is refused:

enum H[T]:
    X(t: T)
    Y
enum G[T]:
    A(h: H[T])
    B(n: i64)
fn show_h(h: H[i64]) -> str:
    match h:
        H.X(t) => f"X {t}"
        H.Y => "Y"
fn main:
    let g: G[i64] = G.A(H.X(3))
    match g:
        G.A(h) => print(show_h(h))
        G.B(n) => print(f"B {n}")

PR #2547 (D144 completed): error: cannot consume read-only view binding 'h'; clone it or transfer from the owner; the fixture behav_generic_enum_nested_generic_payload.w now spells match move g, which is a token no reader thinks means anything: G[i64] and H[i64] are integers in a tag.

Law 1 and D111: values have no identity; D120 stage 3 made a struct of values a value with no impl Copy and left enums opt-in ("an enum instance stays opt-in", Sema.is_copy). The same compositional rule for enums — an enum is a value when every payload is, unless it has a Drop impl or is a resource type — removes the move. It is an ownership question, so a brief for Eric, not delegated. Count in the tree after the sweep: the two fixtures that now spell move for this reason (behav_generic_enum_nested_generic_payload.w; the Option-of-List case in da_c_facade_production_forms.w is a resource and stays).

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced, and the next step is Eric's ruling (ownership, as the report says).

    $ with run main.w   # the report's G/H program
    error: cannot consume read-only view binding `h`; clone it or transfer from the owner
     --> main.w:14:32
    14 |         G.A(h) => print(show_h(h))
    

    What the rulings say. D111: values have no identity, and passing one copies it. D120 stage 3 made a struct of values a value with no impl Copy and left enums opt-in ("an enum instance stays opt-in", Sema.is_copy).

    The question: should an enum be a value (Copy) when every payload is a value, unless it has a Drop impl or is a resource type, as structs already are? That removes the move g this match needs today.

  2. added a commit that references this issue on Oct 29, 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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions