Skip to content

Commit a5b0281

Browse files
committed
Try a more explicit example for partial move destructor.
1 parent 663b0fb commit a5b0281

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/destructors.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ loop {
6363
moved = ShowOnDrop("Drops when moved");
6464
// drops now, but is then uninitialized
6565
moved;
66+
6667
// Uninitialized does not drop.
6768
let uninitialized: ShowOnDrop;
68-
// Only first element drops
69-
let mut partially_initialized = (ShowOnDrop("one"), ShowOnDrop("two"));
70-
core::mem::forget(partially_initialized.1);
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.
7175
}
7276
```
7377

0 commit comments

Comments
 (0)