Issue #2974: A chain over io::lines() whose lambda throws fails in rustc (NK1343, Lines is not an iterator)

Open and answer this issue on GitHub.

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

Probe

use std::io

fn width(l: ref String) -> i64 throws {
    if l.len() > 100 { throw io::IoError::Other("long") }
    return l.len()
}

fn main() throws {
    let s = io::lines().map(fn(l) { width(l) })
    println(f"{s.count()}")
}

It should print the line count, the same way a chain over a list with a throwing lambda does (ADR-loop-failure-v1 D1). It stops with NK1343: rustc reports “nikaia_std::io::Lines is not an iterator”.

The same happens with .filter(..).collect() after the map, and with for n in io::lines().map(fn(l) { width(l) }). It fails on b36e564a and on the binary from before run 6 of #2927 alike.

Traced

emit_stream_chain and emit_stream_kept_steps refuse a step in failing_through_calls (“which the general walk carries”). The general walk then writes io::lines().await.map(|l| -> Result<..> ..), an Iterator adapter that Lines does not have.

To build

  1. Let the stream state that the compiler writes for lines (ADR-chain-loop-v1 D7, #2927 run 6) carry a step whose lambda throws. The failure leaves the loop as ADR-loop-failure-v1 D1 says.
  2. Add a test in tests/compiler/tests/ with the probe above, the filter.collect form and the for form, with stdin, passing in both settings.

Done when

All three forms print what the same chain over a list prints, and the lines, stream, failing and chain test groups stay green.

Found in run 6 of “Chains over lists, maps and std’s other producers are one loop the compiler writes, and seq.rs leaves Rust (ADR-chain-loop-v1 D6, D7)” (#2927).

Back to Open Issues