Status: Accepted
Date: September 26, 2026
Answers: #220’s a filter lambda that compares its item
fails in rustc
Related: ADR-184 D2 (a view of text is a &str),
ADR-105 (Seq), ADR-094 D2 (a parameter only read
is lent)
let a = "a-b".chars().filter(fn(c) { c != '-' }).count() // rustc: &char against char
for x in xs.iter() { if x > 2 { … } } // rustc: mismatched types
let k = h.keys().filter(fn(k) { k != "b" }).count() // rustc: &String against str
Below, a view is a
reference, and a program that reads a number through one and compares it with
a number is rustc’s error. Three places put one there: a walk over views of
numbers (xs.iter() is Seq[ref i64]), filter, whose lambda the language
below hands a reference to the item, and keys() and values(), which the
ledger said yield values while they yield views.
Where a method hands back a sequence of views of numbers, truth values or
characters, its items are the values: the checker types them so and the
emitter writes .copied() after the call. Copying an i64 costs less than
pointing at one, so this is the cheaper representation and not a concession,
and it is what the program reads.
filter’s lambda takes its item, where the item copies, by pattern.The language below hands filter’s lambda &T. Where T copies - a number, a
character, a view of text or of anything - the parameter is written |&x| and
is the item. Where it does not - text of its own, a struct - &T is left, and
reads as the item through the language below’s own dereferencing: s.len(),
s != "x" and p.x all do.
keys() and values() hand back views.They point into the map, and the ledger says so: Seq[ref $K] and
Seq[ref $V]. A map of numbers yields numbers by D1.