Skip to content

Field value read through shared borrow moves out of the borrow (blanks caller state / aliases buffer) #780

Closed

Description

@ehartford

Repro

type F { name: str }

fn get_name(f: &F) -> str: f.name

fn get_name_ret(f: &F) -> str:
    if f.name.len() > 0:
        return f.name
    "empty"

fn main:
    let f = F { name: "hello" ++ "" }
    print(get_name_ret(f))   # hello
    print(get_name_ret(f))   # empty  <-- f.name was BLANKED through the borrow

Actual MIR

  • Explicit return: _0 = move _1.*.f350; _1.*.f350 = const zst — moves AND blanks the caller's field through the &F param.
  • Tail form: _0 = move _1.*.f350 with no blank — caller and callee then both own the same buffer (latent double free).

Expected (D22)

An owned-value demand on a place rooted through a shared borrow materializes an independent value (for str: concat copy), or is rejected. It must never move out of borrowed content.

Impact found in the wild

analysis_fact_field (return fact.name through &AnalysisFact) blanked every fact name during the filter pass, so any second render (the matrix:name~… needs-codegen path) matched zero rows — deep-debug-tool-tests' analyze-matrix probe failure, plus the corrupt-vec-header panic on the same run.

Fix landed

MirLower NK_FIELD_ACCESS value arm: when the base chain passes through a &T link and the field is str, emit the two-part RK_STR_CONCAT_N [copy place, ""] independent copy instead of OK_MOVE.

Residue (this issue tracks it)

  • Non-str drop types (Vec, HashMap, user Drop structs) through a shared borrow still move out (same corruption class).
  • Sema should either reject or record the materialization uniformly (the lowering-side gate is a physical fix).
  • Read receivers typed as the value type (IndirectPlace self) are not covered by the &T-typed-base detector; verify and extend.

Activity

  1. ehartford commented on Aug 31, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-08-31: CLOSE (overcome by events). D32 (§2.2, landed 839696a) makes every form in this issue a compile error: str via return f.name, the non-str Drop-type variant, and the read-receiver self.name all reject with "a field never moves out implicitly (§2.2, D32)" (three probes, 2026-08-31). The move-out-through-borrow corruption class is unrepresentable.

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