Open and answer this issue on GitHub.
bug, ready · opened 2026-11-29 · updated 2026-11-29 · 0 comments
Over io::lines():
use std::io
fn main() throws {
let mut ss = []
let n = 1
ss.push(io::lines().filter(fn(l) { l.len() >= n }).take(1))
for s in ss.drain() { println(f"{s.join("|")}") }
}
Over a list:
fn main() throws {
let xs = [1, 2, 3]
let mut ss = []
for i in 1..3 { ss.push(xs.iter().filter(fn(x) { x >= i })) }
for s in ss.drain() { println(f"{s.count()}") }
}
On c2554dfb both give NK1343 (rustc: n, or i, does not live long enough).
The first probe prints the first line of length 1 or more. The second prints 3, then 2. Part II says Seq::filter is lazy and keeps its lambda.
emit_core_argument writes a lambda handed to a lazy step as a borrowing closure, without move, so a kept step outlives the names it reads. The lowered closure is |&l: &&str| { (l.len() as i64) >= n }, in the state’s constructor.
.stdout (and the .stdin for the first).Both probes print as expected.
Found during “A chain over io::lines() is one loop the compiler writes, a kept chain a state it writes, and the view steps leave Rust (ADR-chain-loop-v1 D6, D7)” (#2899).