Issue #1065: A call through a struct field holding code passes its arguments unlent: a list to ref Vec[i64] reaches rustc as Vec, an owned text is moved

Open and answer this issue on GitHub.

ready, wip · opened 2026-10-31 · updated 2026-10-31 · 1 comment

Found by b12 (#1061, report docs/briefs/bugs/b12-1061-pausing-two-view-field.md.report.md), narrowed by the architect on 46e6179f.

Problem

A call through a struct field holding code does not lend its arguments: a list handed to a ref Vec[i64] parameter reaches rustc unborrowed, and an owned text handed to a String parameter (a view by ADR-282 D2) is moved. The same call through a let or a parameter (g(x), apply(count, x)) is right. Not about pausing: the field is sync or not, one view or two.

Probe

struct H { f: fn(ref Vec[i64]) -> i64 }
fn count(a: ref Vec[i64]) -> i64 { a.len() }
fn main() {
    let h = H { f: count }
    let x = [1, 2, 3]
    println(h.f(x))          // rustc: Mismatched types, expected `&[i64]`, found `Vec<{integer}>`
}

Row b: struct H { f: fn(String) -> i64 }, let s = f"ab{n}", println(h.f(s)) then println(s): rustc Borrow of moved value: s. Row c (b12’s): struct H { f: fn(ref Vec[i64], ref Vec[i64]) -> ref Vec[i64] }, h.f(x, y).len(): Arguments to this function are incorrect.

Cause (traced, fairly sure)

To build

  1. Checker: record the lent arguments of a field call (check_core_call_lent with the found types).
  2. Emitter: lend what the checker lent in emit_core_a_field_call (as emit_core_args does), for rows a-c.
  3. Test tests/compiler/tests/a_field_call_lends.nika + .stdout with rows a-c, failing on the unfixed binary.

Generated by Claude Code

Comments

keywan-ghadami, 2026-10-31

Second probe (b12 report, 2026-10-31): struct H { f: fn(ref Vec[i64], ref Vec[i64]) -> ref Vec[i64] }, h.f(x, y) with let x = [1, 2, 3] reaches rustc with Arguments to this function are incorrect (expected &[i64], found Vec), also with sync. Brief docs/briefs/bugs/b16-1065-field-call-lends.md, next bug batch.


Generated by Claude Code

Back to Open Issues