Skip to content

Checker accepts owning-field read through a view as a silent aliasing bit-copy (move-out-of-borrow unrejected) #730

Closed

Description

@ehartford

Class

owned_local = (&container[i]).owning_field compiles silently. For a non-Copy
field type (Vec-bearing struct, pool, list) the compiler emits a bit-copy of the
handle, so two owners share one buffer: the local's scope-exit drop frees the
container element's buffers while the element keeps its pointers. Rust-safety
requires this to be rejected (cannot move out of a borrow) or satisfied by an
explicit clone; D22 says a &T materializes an independent T only under owned
demand — an aliasing bit-copy is not independent.

Sibling of #715 (element copies via vec[i]/vec.get) — this is the field
projection through a reference
shape, so the #607/#715 gate discussion doesn't
cover it.

Manifestation (proven, fixed at the use site in 4e7294f)

The lsp-use-std selfhost case crashed release-only with
panic: integer overflow: i64 multiplication out of range after a correct
completion response. Watchpoint timeline on the corrupted header:

  1. LspState.publish_diagnostics ran dl = (&self.documents[idx]).cached_diags;
    dl's drop walked the document's cached DiagnosticList, blanked each
    Diagnostic's nested vec header, freed the buffers (document kept pointers).
  2. LspState.completion's str_concat_n_copy reused the freed block for the
    response JSON.
  3. Shutdown drop of LspState.documents walked JSON bytes as Vec headers;
    with_vec_free_drop_origin panicked on cap * elem_size over garbage.

Six LSP functions had the same merge-into-owned-local shape; all were converted
to if-expression view joins in 4e7294f. The compiler still accepts the pattern
everywhere else.

Repro shape

type Inner { items: Vec[i32] }
type Outer { inners: Vec[Inner] }
...
let v = &outer.inners[0 as i64]
let copy = v.items        // should be rejected or deep-cloned; today: bit-copy
// copy's drop frees outer.inners[0].items' buffer; Outer's drop frees it again

Expected

A diagnostic at the read site (move out of borrow requires clone), or D22
materialization as a genuinely independent value. Silent aliasing is the one
outcome that cannot stay.

Activity

  1. ehartford commented on Jul 27, 2026

    @ehartford
    ContributorAuthor

    Fixed in eb0a0cf (isolated battery green including move/drop audits, reseeded).

    Per D22 rule 3 and §13.6 the resolution is rejection, not an implicit clone: an owned demand may be satisfied from &T only when T is Copy, and the ruling explicitly forbids satisfying it through a hidden Clone. Field access through a shared view now records the non-Copy projection, and the owned-demand consumption sites (let bindings, assignments) reject it with a message naming the type and the three legal repairs — borrow the field, clone it, or restructure so the owner transfers. Reads, borrows, receivers, and Copy leaves are unaffected.

    First catch was in the compiler itself: comptime_eval_finish drained four owned members (pending diag, extras, effect records, synced sema) out of a &ComptimeEvaluator; it now consumes, which is what the body always meant. Pinned by test/compile_errors/err_view_field_steal_non_copy.w and test/behavior/behav_view_field_copy_leaf.w.

    Follow-up tracked separately: call-argument and struct-literal-field owned demands are not yet gated by the same fact table — same helper, more consumption sites.

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