You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
-mm=own: a let assigned a new value after its value moved is still treated as moved #528
Under -mm=own, once a let has given its value away, assigning it a new object does not make it an owner again. A later read is reported as a use after the move, or as a borrow outliving an overwrite. Rust accepts both shapes: assigning to a moved-from binding gives it a fresh value. Both programs print 1 2 under -mm=rc and -mm=gc.
Moved into a field
classNode{constructor(publicvalue: number){}}classHolder{node: Node;}functionmain(){consth=newHolder();leta=newNode(1);h.node=a;// the first Node moves into ha=newNode(2);// a owns a new Nodeprint(h.node.value,a.value);}
reassign.ts:9:25: error: 'this value' is used here after its value was moved
print(h.node.value, a.value);
^
reassign.ts:7:5: note: value moved here
h.node = a; // the first Node moves into h
^
Moved into another local
classNode{constructor(publicvalue: number){}}functionmain(){leta=newNode(1);letb=a;// the first Node moves into ba=newNode(2);// a owns a new Nodeprint(b.value,a.value);}
reassign2.ts:7:11: error: 'this value' borrows 'this value' but is used here after 'this value' is released or overwritten
print(b.value, a.value);
^
reassign2.ts:6:5: note: 'this value' is released or overwritten here
Here b borrows a instead of taking it over, because a is read again later. The overwrite then ends the borrow, even though the later read is of the new value.
Expected
Both programs compile and print 1 2. The assignment a = new Node(2) ends the old value's story for a. The moved-from slot holds nothing to release, and reads after the assignment see the new owner.
Notes
The diagnostics name every place 'this value'. Naming the variable would help.
Activity