Skip to content

Positional collections have two spellings for one meaning: xs[i] and xs.get(i); keep [i] #1239

Closed

Description

@ehartford

Eric, 2026-09-20: "get(1) shouldn't even be the way to access it, it should be [1] not get(1) unless there's a really good reason to have two spellings."

Today (D27, spec §13.x, CLAUDE.md): xs[i] denotes the element place and xs.get(i) returns &T, read-only, panicking out of range. On a positional collection the two observe the same element with the same failure mode: one meaning, two spellings. The mission says a default or a second spelling never selects between meanings, and a spelling that adds nothing is ceremony.

What the references do. Rust has both, but they mean different things: v[i] panics, v.get(i) returns Option — a real reason to have two. Go, Swift, Zig, Mojo and Vale index with [i] only. With's .get(i) has no such second meaning (D27 reserves Option-returning get for keyed maps, where absence is normal).

Proposal. xs[i] is the one user-facing spelling on Vec, arrays and slices. .get(i) on positional collections is removed from the user surface (a trait method may keep a name for implementations, but user code never writes it). The cheat-sheet in CLAUDE.md/AGENTS.md already says line.split("\t")[1] (changed on the #962 fix branch).

Cost. The compiler, stdlib, tests and tools use .get(i) on Vec pervasively (the legacy get(x as i64) idiom). Retiring it is a mechanical rewrite (with -p / a Lexer-based tool), then a diagnostic on positional .get( naming [i].

Needs: Eric's ruling amending D27, and the exact spec words. Related: #962 (a view into a temporary — bites [1] and .get(1) alike; fix on branch reject-view-into-temporary).

Activity

  1. ehartford commented on Oct 2, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by 9a73f74 (#1968): Sema refuses Vec.get naming xs[i] (D71, README v7.4); the c-facade renderer and derive(SoA) emitters updated; tools/migrate_vec_get.w rewrote 876 + 48 in-tree sites; two compile_errors fixtures pin the diagnostic. Battery green on stack #1972. Noted out of scope on the PR: SortedVec.get(index) in lib/std and the derive(SoA) row accessor still exist (the issue names Vec/arrays/slices).

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