On 2014-06-12, at 20:59, Corey Richardson <[email protected]> wrote:
> Implicit cloning is a non-starter. Clones can be very expensive.
> Hiding that cost is undesirable and would require adding Clone to the
> language (it's currently a normal library feature).
But I think it will be easy to make the error of writing the explicit .clone()
in places where it's not needed. For example:
fn foo<T>(value: T) {}
let x = box 123;
x.clone().foo();
x.clone().foo();
...given that `x` is not used after those lines, the last call to .clone() is
unnecessary. Whereas, if the task of cloning (implicitly) is assigned to the
compiler, then the compiler can use static analysis to make sure such
programming errors never occur. The example above would become something like:
fn foo<T>(stable value: T) {}
let x = box 123;
x.foo(); // here `x` gets cloned here
x.foo(); // here `x` doesn't get cloned because this is the last use of `x`
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev