You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
§13.5 implicit .iter() is not implemented for types other than Vec/HashMap/BTreeMap (SortedVec, Trie, user types) #1837
§13.5 For-In Loops, Implicit iteration: "When it does not implement Iter[T] but has an .iter() method that returns an Iter[T], the compiler inserts .iter() automatically."
Repro
use std.collections.sorted_vec
fn main:
var s: SortedVec[i32] = SortedVec.new()
s.insert(3)
for x in s:
print(f"{x}")
error: MIR lowering failed for function 'main' in sv.w; AST codegen was removed, so this function cannot be compiled
for x in s.iter(): prints 3.
Cause
Only Vec, HashMap, BTreeMap (and & of them) get the implicit form, each special-cased in SemaCheck.infer_for_element_type and MirLower.lower_for. For any other type Sema fell through to an i32 element type (the #1828 fallback) and MIR tried to call next() on the collection itself (lower_for, callee_sym == next_sym → mark_unsupported).
Expected
Sema resolves the .iter() call for the loop (receiver mode, generic specialization, the @[iter_of_self] borrow of the collection) and records it under the for node; MIR lowers that call and steps the returned iterator with the existing next() protocol.
Interim
The #1828 fix makes Sema refuse this loop with a named diagnostic pointing at .iter() instead of failing in MIR. Workaround: spell .iter().
Fixed on main by 7b56d3f (stack #1979, battery green on 029574d). for x in c inserts .iter() for any type whose iter() returns an Iter[T] (§13.5); Sema records it, MIR lowers it; SortedVec, user types, &T and generic fixtures.
Activity
Sema/MIR: for over a non-iterable is refused; one-clause for over Opt…
c_import/migrate/emit-c: no `-> Unit` on void C fns (#1838); header f…
ehartford commentedon Oct 3, 2026
Fixed on main by 7b56d3f (stack #1979, battery green on 029574d).
for x in cinserts.iter()for any type whose iter() returns an Iter[T] (§13.5); Sema records it, MIR lowers it; SortedVec, user types, &T and generic fixtures.