On Tue, Feb 25, 2014 at 03:18:19PM -0800, Kevin Ballard wrote:
> If you can construct the new value independently of the old, sure. But if 
> constructing the new value
> requires consuming the old, then you can't.

I think lifting restrictions on moves beyond trvivial cases is going
to turn out very subtle, if it is possible at all. The biggest
challenge has to do with failure. For example, if I have some code
like:

    enum List<T> { Cons(T, ~List<T>), Nil }

    *list = ~Cons(xxx, *list);

In the zeroing world we have today, this seems like something we
cannot support at all, at least not if memory alloc failure is
recoverable (something I know has been debated).  The problem is that
the `~` may fail to allocate, causing destructors to run, and they
would observe that `*list` has been moved.

Without zeroing, it is...plausible that this could work -- after all,
*list is logically deinitialized, but the value remains valid, and in
this particular case we can probably deduce that no alias to *list
remains, because we know what variant constructors do. But that's
pretty subtle stuff and doesn't generalize very far.  Certainly we
could never permit calls into arbitrary user code while an `&mut`
referent is borrowed.

That said, this is still a generalization on swap, in that you can
rotate any number of values; but we could add unsafe helpers to do
that.


Niko
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to