Allow the use of self if a field is moved and assigned a new value
yorickpeterse opened this issue · comments
Description
fn move
methods should be able to continue using self
after one or more fields are moved, provided those fields are assigned a new value, similar to how we allow one to continue using moved variables inside loops that are assigned new values. This would allow for code such as this:
fn move foo -> Thing {
@some_field = match @some_field {
case ... -> 42
...
}
self
}
Currently to work around this limitation one would have to use match ref @some_field
.
Related work
No response
For this to work, we need to keep track of what fields are moved and "untrack" those when they are assigned a new value again. Only when there are no moved fields can we allow the use of self
. Tracking fields could just be a counter, as fields can't be moved multiple times and assigning them a new value "unmoves" them.