Clone
is a normal library trait, and requires normal (library) implementations, for all types. For example, Clone
is implemented for &T
right here, in the form:
impl<'a, T> Clone for &'a T {
/// Return a shallow copy of the reference.
#[inline]
fn clone(&self) -> &'a T { *self }
}
Hence, everything of the form &T
is Clone
able... where T
a concrete type. And that's the clincher: &Trait
is not (yet) a type of the form &T
with T = Trait
(but rather an "atomic"/primitive type that can't be separated into parts), so it is not covered by that impl
.
We require dynamically sized types (DST) for the compiler to be able to reason about passing just plain old Trait
around as a generic parameter (Nick Cameron is actually hard at work at some parts of the DST implementation, so this will hopefully happen soon).
You can, however, manually implement Clone
for your traits of interest, e.g. the following works well:
trait Foo {}
impl<'a> Clone for &'a Foo {
fn clone(&self) -> &'a Foo {
*self
}
}
However, it only works for traits defined in your current crate, or else the compiler has concerns about coherence (e.g. changing Foo
to Eq
in the impl
above causes error: cannot provide an extension implementation where both trait and type are not defined in this crate
).