Skip to content

Auto-ref does not fire for a generic parameter bound &C — count_all(v) rejected where count_all(&v) works #737

Closed

Description

@ehartford
use std.collections

fn count_all[C: IntoIter[i32]](c: &C) -> i32:
    var walker = c.iter()
    ...

fn main:
    var v: Vec[i32] = Vec.new()
    v.push(1)
    print(int_to_string(count_all(v) as i64))     // rejected
    let vr = &v
    print(int_to_string(count_all(vr) as i64))    // works

Rejection:

= note: argument 1 expects &i32
= note: actual type: Vec[i32]

Two things wrong. The auto-referencing rule (CLAUDE.md: "peek(x) is the
ordinary spelling when peek takes &T") does not fire when the parameter is
&C for a generic C — the caller is forced to spell &v, which is exactly
the ceremony the mission forbids. And the diagnostic reports the expectation as
&i32 (the trait's element type) rather than &C/&Vec[i32], so it points at
the wrong type entirely.

Found while verifying #716's iter()-on-borrowed-receiver conformance (that part
now works; this is the generic-parameter auto-ref gap next to it).

Activity

  1. ehartford commented on Jul 28, 2026

    @ehartford
    ContributorAuthor

    Fixed in 9c3b761 (battery green: build, fixpoint, :test, :move-audit, :drop-audit; seed + installed compiler now v0.15.1-g9c3b76193).

    Two exact-line root causes, both proven before fixing (lldb backtrace + --dump-abi):

    1. bind_type_params_from_type_expr's NK_TYPE_REF arm only bound the pointee when the argument was itself a reference — the auto-ref spelling count_all(v) left C unbound, and the silent unbound-param default then made C = i32, which is where the phantom 'expects &i32' came from. The arm now binds the pointee from the place type, per §3.8. The silent i32 default itself is a separate no-silent-fallback violation, filed as Uninferable-but-mentioned generic type param silently defaults to i32, producing phantom 'expects &i32' diagnostics #738.
    2. check_call's unknown-signature path conservatively marked every non-Copy argument moved, and a generic callee always reaches it (no sig until specialization) — so even after inference the plain spelling consumed v (let vr = &v after the call reported use-of-moved). Arguments bound to a declared &T param now skip the conservative marking; the signature is authoritative.

    Behavior fixture issue737_generic_ref_param_autoref.w pins both spellings, post-call liveness of the argument, and unbounded [T] auto-ref. Bonus from the same battery cycle: the reseeded gate-bearing seed caught two real Drop-element copies in build/emit_c.w that no earlier battery could see (build scripts compile under the seed) — fixed in 757bfc1.

  2. added 2 commits that reference this issue on Aug 9, 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

    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