Description
Since move
is already a keyword, I propose the following:
&move T
indicates a move reference to T
. A move reference implicitly moves out of whatever it borrows, and dereferencing it consumes the reference, yielding a value of type T
, but it may also be borrowed as &T
and &mut T
. &move T
is NOT copy
, and does not allow reborrowing like &mut T
does. The borrowed variable is considered dropped at the end of the lifetime of the &move T
by borrowck. Drop::drop() will be implicitly called.
&move mut T
indicases an output reference to T
. An output reference is considered an uninitialized variable by the borrowchecker. Only an uninitialized variable can be borrowed as &move mut
, and it is considered initialized by borrowck after the end of the lifetime of the &move mut
. Once initialized, it is considered identical to &mut T
.
&move T
is the owning reference that a lot of people have been wanting for a while, and &move mut T
is my idea for a generalized placement new syntax, which might be necessary when/if we support unmovable types. An alternative to &move mut T
would be a combination of placement syntax and guaranteed return-value optimization for functions returning unmovable types; I suppose the latter would be necessary anyway for them to work at all.
Thoughts? Reasons why this wouldn't actually parse? Alternative syntax?