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
for with a refutable pattern over consuming iteration leaks every skipped element #1490
Spec: §13.5 — "Refutable patterns are allowed; elements that do not match are skipped and iteration continues." Skipping an owned element (consuming iteration) must still drop it: §2.4 / the mission (a leak is a defect).
fn main:
var ps: Vec[(i32, str)] = Vec.new()
ps.push((0, "a".clone()))
ps.push((1, "b".clone()))
var n = 0
for (0, s) in ps.into_iter():
n = n + s.len() as i32
print(n)
run --debug-alloc (stage1 of origin/main ba2d5d1): prints 1, then LEAK size=16, leak count=1 — the skipped (1, "b")'s str.
MIR of main: the pattern test's fail edge is switchInt(copy _19) -> [1: bb12, otherwise: bb7] — bb7 is the loop header; the item local _18 (the moved-out (i32, str)) is never dropped on that edge.
Exact line: MirLower.bind_for_element_or_skip, self.lower_pattern_match(item_place, pat_or_sym, matched_bb, continue_bb) with continue_bb = the header: the non-matching edge carries an owned item with no drop. A view iteration (for (0, s) in ps) is unaffected (the item is a reference).
Fix shape: route the fail edge through a block that drops the item (when its type needs drop) and then continues — what the #1403 PR does for comprehension clauses (lower_comprehension_skip_block).
Found while building the #1403 comprehension matrix.
Activity
MIR: a comprehension clause's refutable pattern skips what it does no…
MIR: a comprehension clause's refutable pattern skips what it does no…
Ownership: validate-ownership sees leaks (Reset state); drop exactly …
ehartford commentedon Sep 26, 2026
Fixed by #1718 (drop cluster). Verified on main 3ccb998: the issue's repro under
run --debug-allocprints1, leak count=0 (was LEAK size=16).