Issue #2933: A kept lazy step whose lambda reads a local does not compile when the step outlives the local (rustc: does not live long enough)

Open and answer this issue on GitHub.

bug, ready · opened 2026-11-29 · updated 2026-11-29 · 0 comments

Probes

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).

Expected

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.

Suspected cause

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.

To build

  1. A lambda handed to a step that is kept takes the values it reads with it: a copy for scalars, a view or move as the sharing walk decides otherwise.
  2. Both probes become tests with their .stdout (and the .stdin for the first).

Done when

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).

Back to Open Issues