Issue #2968: A filter after a map over a range with two literal ends fails in rustc (NK1343, |x| where |&x| is needed)

Open and answer this issue on GitHub.

bug, ready · opened 2026-11-30 · updated 2026-11-30 · 1 comment

Probe

fn main() throws {
    let f = (0..<100).map(fn(i) { i * i }).filter(fn(x) { x > 40 }).count()
    println(f"{f}")
}

It should print 93. It stops with NK1343: rustc reports mismatched types and suggests dereferencing the borrow. This happens with target/fast/nikaia built at fc8c6134 and at f9dd6522 alike. The chain goes the adapter path, because the chain loop of ADR-chain-loop-v1 D6 keeps a filter ended by count on the adapters (rule 4).

The lowered Rust writes .filter(|x| { x > 40 }). A range with a typed end writes |&x|.

Similar shapes that work

Traced

check_core_method.nika writes filter_patterns with an unknown item only where open_items_of(receiver) names an open number. open_walks holds the range’s walk, but not the map call over it. So the map’s item, an open number, is unknown and has no open walk.

This may share the cause of #2947 (the open number of a literal range’s chain).

To build

  1. Give the map call over a literal range the open walk of its range, so the map’s item is known as an open number for the steps after it.
  2. Add a test in tests/compiler/tests/ with the probe above and 93 as its stdout, passing in both settings.

Done when

The probe prints 93 in both settings, and the range, map, chain and filter test groups stay green.

Found in the run that built “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), run 4.

Comments

keywan-ghadami, 2026-11-30

Two more forms with the same open-number cause, found in run 5 of #2927. Both give NK1343, on that run’s binary and on fc8c6134 alike. The loop writes __nikaia_apply(&__nikaia_item, |i| { big(i) }) with no |&i|.

fn big(i: i64) -> bool { return i > 50 }

// in place
let u = (0..<100).map(fn(i) { i + 1 }).find(fn(i) { big(i) }) ?? 0

// kept in a name
let r = 0..<100
let v = r.find(fn(i) { big(i) }) ?? 0

With let n: i64 = 100 and 0..<n, both print 51.

To build, in addition: a test with these two forms beside the first probe.


Generated by Claude Code

Back to Open Issues