Skip to content

Commit b4b3536

Browse files
authored
Merge pull request #648 from ehuss/partially-initialized-drop
Update partially initialized values in drop documentation.
2 parents e922989 + a5b0281 commit b4b3536

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/destructors.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ loop {
6363
moved = ShowOnDrop("Drops when moved");
6464
// drops now, but is then uninitialized
6565
moved;
66+
67+
// Uninitialized does not drop.
6668
let uninitialized: ShowOnDrop;
67-
// Only first element drops
68-
let mut partially_initialized: (ShowOnDrop, ShowOnDrop);
69-
partially_initialized.0 = ShowOnDrop("Partial tuple first");
69+
70+
// After a partial move, only the remaining fields are dropped.
71+
let mut partial_move = (ShowOnDrop("first"), ShowOnDrop("forgotten"));
72+
// Perform a partial move, leaving only `partial_move.0` initialized.
73+
core::mem::forget(partial_move.1);
74+
// When partial_move's scope ends, only the first field is dropped.
7075
}
7176
```
7277

0 commit comments

Comments
 (0)