←back to thread

128 points RGBCube | 1 comments | | HN request time: 0s | source
Show context
jhugo ◴[] No.44498376[source]
> we cannot just require all generic parameters to be Clone, as we cannot assume they are used in such a way that requires them to be cloned.

No, this is backwards. We have to require all generic parameters are Clone, as we cannot assume that any are not used in a way that requires them to be Clone.

> The reason this is the way it is is probably because Rust's type system wasn't powerful enough for this to be implemented back in the pre-1.0 days. Or it was just a simple oversight that got stabilized.

The type system can't know whether you call `T::clone()` in a method somewhere.

replies(4): >>44498401 #>>44498749 #>>44499040 #>>44499325 #
chrismorgan ◴[] No.44499040[source]
> The type system can't know whether you call `T::clone()` in a method somewhere.

It’s not about that, it’s about type system power as the article said. In former days there was no way to express the constraint; but these days you can <https://play.rust-lang.org/?gist=d1947d81a126df84f3c91fb29b5...>:

  impl<T> Clone for WrapArc<T>
  where
      Arc<T>: Clone,
  {
      …
  }
replies(1): >>44499948 #
jhugo ◴[] No.44499948[source]
Yeah. My bad. I got annoyed by the "is broken" terminology of TFA and wasn't thinking clearly :/
replies(1): >>44499988 #
1. chrismorgan ◴[] No.44499988{3}[source]
I did the same… I just deleted my comment quickly when I realised I had erred!