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
clone() is unknown on a tuple, an array, Option and Result #2161
let t = ("a".to_upper(), 1)
let u = t.clone() // unknown method 'clone' for type '(str, i32)'
let o: Option[str] = Some("x".to_upper())
let p = o.clone() // unknown method 'clone' for type 'Option[str]'
let arr = ["a".to_upper(), "b".to_upper()]
let brr = arr.clone() // unknown method 'clone' for type '[2]str'
Spec: §11.8 gives derive(Clone) ("all fields are Clone: field-by-field clone") for declared types. Nothing says a tuple or an array of Clone elements is Clone, and Option/Result in lib/std declare no Clone. D44 and §13.3 make clone the spelling of an independent collection (m.keys() |> map(it.clone()) |> collect[Vec]()), so a Vec[(str, i32)] has no way to produce owned pairs from a traversal.
Why now: it blocks #2145 (v.iter() yielding views): xs.iter() |> map(it.clone()) |> collect[HashMap[str, i32]]() over Vec[(str, i32)] is the conforming spelling and does not compile.
Proposed:
Option[T] and Result[T, E] are Clone when their arguments are: two impls in lib/std, plain With.
Activity
std: Option and Result are Clone when their payloads are (#2161)
std: Option and Result are Clone when their payloads are (#2161) (#2164)
ehartford commentedon Oct 5, 2026
Option and Result are Clone on main a57d2d2 (#2164). Tuples and fixed arrays still have no
clone: that needs a spec sentence (asked of Eric).spec v7.24 (D95): let _ drops; pub const takes its value's type; ?? b…
spec v7.25 (D96): a key is any structurally comparable value; a key p…
D95 + D96: let _ drops; pub const takes its value's type; ?? below |>…
ehartford commentedon Oct 5, 2026
Fixed on main by stack #2196 (merged as efb765c), battery green on a21e326; the regression test for it landed with the fix.