You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
D111 non-compliance: an owned str demand does not materialize a &str through Ok-wrap, collect, or a &&str join #2271
D111 (docs/meetings, Eric 2026-10-08): "str is a value. Passing a str always copies. Code using str never sees 'use of moved value' and never needs .clone()." D22 §6.2: an owned demand is met by a copy of a Copy pointee.
The D111 test/example sweep left these .clone()s in place because removing them does not compile. Each is a demand for an owned str that the compiler does not meet:
Implicit Ok tail (behav_implicit_result_tail_ownership):
fn direct(text: &str) -> Result[str, str]: text
error: return type mismatch. A plain -> str return copies; the implicit Ok-wrap does not carry the demand to its payload.
collect of &str views into an owned collection (map_snapshot_cases, behav_d44_map_traversal_views, issue58_hashmap_keys_str, da_2165_collect_duplicate_key):
error: return type mismatch (the pipeline is Vec[&str]). collect[HashSet[str]]() over &str items: collect[HashSet[T]] element type does not match iterator element type. With an inferred element, the generic instance in std/collections.w:773 reports a view escape (view out may originate from x). D44 spells the owned collection map(it.clone()); under D111 the .clone() is ceremony, and the demand (the declared Vec[str], HashSet[str]) should copy each element.
A &&str arm meeting a str result (behav_1810_str_view_lookups):
fn first_some(o: &Option[&str]) -> str:
match o:
Some(s) => s
None => "none"
error: match expression of type &&str cannot produce str. A single &str arm works; contextual Copy materialization stops after one dereference.
Each site still carries its .clone() on the D111 stack; the census counts them (with run tools/ceremony_census.w --sites str-clone).
State on branch d115-d120 (commit 02bf556), checked by running, not by notes:
Shapes 1 (implicit Ok tail, fn direct(text: &str) -> Result[str, str]: text) and 3 (a &&str arm meeting a str result) compile on main since #2337; their test clones are gone (behav_implicit_result_tail_ownership, behav_1810_str_view_lookups). collect[HashSet[str]]() over a List's &str items also works (da_2165 clones gone).
Still open, one shape: m.keys() |> map(it) |> collect[List]() and the annotated let ks: List[str] = … over a map's key or value views. Two separate defects behind it:
iter_collect[T, I: Iter[T]] builds a List[&str] the user cannot spell (var out: List[&str] is refused as an ephemeral reference in a container); under D111/D22 §6.2 the collection stores its element, so the owned demand should copy each &str into a List[str]. The generic that does that needs a view-element bound (I: Iter[&T]), which the parser rejects today (expected pattern).
Through Mapped.next() (a result returned by an indirect call (self.f)(x)) the view's origin is lost, so inside the iter_collect instance Rule 6 reports view out may originate from x; the same pipeline over a ListIter records no origin at all and passes silently. A view returned by a call through a fn(&T) -> &U value should originate from its view arguments (the D122 principle applied to callable values).
The .clone()s in issue58_hashmap_keys_str (both), behav_d44_map_traversal_views and lib/map_snapshot_cases stay until those land.
Re-checked on main 811a777 (2026-10-12), by running:
The parser half is ** gone**: fn c[T, I: Iter[&T]](iter: I) -> List[T] with the copying body parses, checks, and runs over m.keys() (prints the right count). The "expected pattern" in the earlier comment reproduces only when the parameter is named it — that name is the pipeline placeholder and cannot be declared (filed as Parser: a parameter named it fails with "expected pattern" and no hint that it is reserved #2382 for the diagnostic wording). Whether a parser fix also landed since, the bound itself is fine today.
Two defects remain, both in the collect[List]() path over map key/value views:
let ks: List[str] = m.keys() |> collect[List]() → "type mismatch in binding": collect builds List[&str]; the owned List[str] demand does not select/copy per element (the hand-rolled Iter[&T] collect above shows the shape std needs).
m.keys() |> map(it) |> collect[List]() → Rule 6 inside std iter_collect (collections.w:760, "view out may originate from x"): a view returned through the callable value in Mapped.next() loses its origin — the D122 principle for callable values, as the last comment said.
So the remaining work is: origin propagation through an indirect call whose callee type is fn(&T) -> &U, and an owned-demand collect for view elements in std. The four .clone() sites stay until both land.
Activity
d111 demands (#2337)
ehartford commentedon Oct 11, 2026
State on branch d115-d120 (commit 02bf556), checked by running, not by notes:
Shapes 1 (implicit
Oktail,fn direct(text: &str) -> Result[str, str]: text) and 3 (a&&strarm meeting astrresult) compile on main since #2337; their test clones are gone (behav_implicit_result_tail_ownership, behav_1810_str_view_lookups).collect[HashSet[str]]()over a List's&stritems also works (da_2165 clones gone).Still open, one shape:
m.keys() |> map(it) |> collect[List]()and the annotatedlet ks: List[str] = …over a map's key or value views. Two separate defects behind it:iter_collect[T, I: Iter[T]]builds aList[&str]the user cannot spell (var out: List[&str]is refused as an ephemeral reference in a container); under D111/D22 §6.2 the collection stores its element, so the owned demand should copy each&strinto aList[str]. The generic that does that needs a view-element bound (I: Iter[&T]), which the parser rejects today (expected pattern).Mapped.next()(a result returned by an indirect call(self.f)(x)) the view's origin is lost, so inside theiter_collectinstance Rule 6 reportsview out may originate from x; the same pipeline over aListIterrecords no origin at all and passes silently. A view returned by a call through afn(&T) -> &Uvalue should originate from its view arguments (the D122 principle applied to callable values).The
.clone()s in issue58_hashmap_keys_str (both), behav_d44_map_traversal_views and lib/map_snapshot_cases stay until those land.D114/D128 gaps (#2333, #2336, #2343), D111 clones (#2271), D115 Amend…
ehartford commentedon Oct 13, 2026
Re-checked on main 811a777 (2026-10-12), by running:
fn c[T, I: Iter[&T]](iter: I) -> List[T]with the copying body parses, checks, and runs overm.keys()(prints the right count). The "expected pattern" in the earlier comment reproduces only when the parameter is namedit— that name is the pipeline placeholder and cannot be declared (filed as Parser: a parameter nameditfails with "expected pattern" and no hint thatitis reserved #2382 for the diagnostic wording). Whether a parser fix also landed since, the bound itself is fine today.collect[List]()path over map key/value views:let ks: List[str] = m.keys() |> collect[List]()→ "type mismatch in binding": collect buildsList[&str]; the ownedList[str]demand does not select/copy per element (the hand-rolledIter[&T]collect above shows the shape std needs).m.keys() |> map(it) |> collect[List]()→ Rule 6 inside stditer_collect(collections.w:760, "view out may originate from x"): a view returned through the callable value inMapped.next()loses its origin — the D122 principle for callable values, as the last comment said.So the remaining work is: origin propagation through an indirect call whose callee type is
fn(&T) -> &U, and an owned-demand collect for view elements in std. The four.clone()sites stay until both land.D111 remainder (#2271): collecting view elements copies them; a calla…