Skip to content

validate-all / audit:all silent on a non-Copy value copied into a consuming call parameter and then dropped by the caller #1742

Closed

Description

@ehartford

Found on branch gen-push-pull (#1725) — CLAUDE.md: a tool that stayed silent is a bug.

While implementing g.pull() (Sema resolves the method syntax to the free generic function std.task.gen_pull(g: impl Gen[T])), MIR's lower_method_call GENERIC_CALL path lowered the receiver through lower_generic_receiver_arg, i.e. as a method receiver: OK_COPY of the caller's place. The callee's parameter is a plain consuming T, so the callee took ownership while the caller still dropped the temporary at scope exit. --debug-alloc reported a DOUBLE FREE of the generator's Vec argument (first free in the caller's scope-exit drop of _13: ty982, second in the callee's closure). --dump-drop-plan showed the caller's drop(_13) ... state_before=Init.

Both check --validate-all ("validate-all: ok") and analyze … audit:all ("violations=0 ok") passed that MIR.

The lowering is fixed on gen-push-pull (Sema records receiver_arg_call_nodes; MIR lowers such a receiver with lower_call_arg), so the pull repro no longer produces the MIR. The validator gap remains: a TK_CALL argument that is OK_COPY of a place whose type is not Copy and needs drop, at a parameter whose declared mode consumes (plain T, not &T, not an in-place receiver), creates two owners and should be rejected by the ownership validator.

To reproduce the silent pass: on gen-push-pull, drop the receiver_arg_call_nodes branch in lower_method_call and run with check r.w --validate-all on

gen fn words(all: Vec[str]) -> str:
    for s in all:
        yield s

fn main:
    var p = words(["x".clone(), "yy".clone(), "zzz".clone()]).pull()
    print(p.next().unwrap())

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