Skip to content

Commit

Permalink
Merge pull request rust-lang#648 from ehuss/partially-initialized-drop
Browse files Browse the repository at this point in the history
Update partially initialized values in drop documentation.
  • Loading branch information
Centril committed Aug 7, 2019
2 parents e922989 + a5b0281 commit b4b3536
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/destructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ loop {
moved = ShowOnDrop("Drops when moved");
// drops now, but is then uninitialized
moved;

// Uninitialized does not drop.
let uninitialized: ShowOnDrop;
// Only first element drops
let mut partially_initialized: (ShowOnDrop, ShowOnDrop);
partially_initialized.0 = ShowOnDrop("Partial tuple first");

// After a partial move, only the remaining fields are dropped.
let mut partial_move = (ShowOnDrop("first"), ShowOnDrop("forgotten"));
// Perform a partial move, leaving only `partial_move.0` initialized.
core::mem::forget(partial_move.1);
// When partial_move's scope ends, only the first field is dropped.
}
```

Expand Down

0 comments on commit b4b3536

Please sign in to comment.