aptos-labs / aptos-core

Aptos is a layer 1 blockchain built to support the widespread use of blockchain through better technology and user experience.
https://aptosfoundation.org
Other
6.07k stars 3.61k forks source link

[Feature Request][Move] Allow a tuple of expression on the lhs of an assignment #14048

Open rahxephon89 opened 2 months ago

rahxephon89 commented 2 months ago

🚀 Feature Request

Currently, Move does not support the syntax:

(*vector::borrow(&mut v, j), *vector::borrow(&mut v, j+1)) = (*vector::borrow(&mut v, j+1), *vector::borrow(&mut v, j));

Because when appearing on lhs, the value inside a tuple can only be a local, a field write, or a deconstructing assignment. It would be nice if we could relax this restriction.

brmataptos commented 2 months ago

Better to support * <expr> as a (sub)Pattern, where <expr> is a &mut, but only in the case of an assignment. That would include the desired case as an instance, while being less hacky.

wrwg commented 2 months ago

I think both the solution discussed here aren't ideal. We do not want to make patterns more powerful then needed in most use cases and keep them clean, so I'm not in favor of extending patterns. We can also not relax something here, like I said in the slack discussion. (This issue text seems to ignore the slack discussion.) Rather we need to make exp = exp assignment work also when lhs is a tuple via syntactic lookaheead. In any case, I don't think this is a very urgent issue.