Skip to content

Commit 651cc12

Browse files
fix(stdlib): Iterator::collect uses [] not nonexistent Vec (#135 slice 4-traits) (#169)
traits.affine:124 was the last parse blocker. Root cause is NOT a compiler grammar gap: `while let` already parses. It is broken stdlib code — `Iterator::collect` returned `Vec[Item]` and used `Vec::new()` / `.push()`, but **`Vec` is not defined anywhere in the stdlib** (the whole stdlib builds lists with `[]` + `++`, never `Vec`; `Vec::new()` also exercised an unsupported `Type::lower_fn()` associated-call form). Resolve-at-source: rewrite `collect` in the stdlib's own list idiom (`let mut result = []; while let Some(item) = self.next() { result = result ++ [item]; } return result`) rather than add speculative `Vec` + associated-function grammar to prop up code that never had a `Vec`. Effect: traits.affine clears its last parse wall (PARSE 124 -> TYPECHECK; the remaining `ref 't ~ Int` is a distinct deeper defect in the `impl Eq for Int` blocks). Pure stdlib change — suite unaffected. Advances #135. Refs #128, #135. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c94461a commit 651cc12

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

stdlib/traits.affine

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,13 @@ pub trait Iterator {
119119
return n;
120120
}
121121

122-
/// Collect into Vec
123-
pub fn collect(mut self) -> Vec[Item] {
124-
let mut result = Vec::new();
122+
/// Collect into a list. (`Vec` is not a stdlib type; the stdlib
123+
/// builds lists with `[]` + `++`, as in prelude/option/result —
124+
/// #135 slice 4-traits.)
125+
pub fn collect(mut self) -> [Item] {
126+
let mut result = [];
125127
while let Some(item) = self.next() {
126-
result.push(item);
128+
result = result ++ [item];
127129
}
128130
return result;
129131
}

0 commit comments

Comments
 (0)