Skip to content

Commit

Permalink
Update partially initialized values in drop documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Aug 6, 2019
1 parent 1528956 commit c85e5a7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/destructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
When an [initialized] [variable] in Rust goes out of scope or a [temporary]
is no longer needed its _destructor_ is run. [Assignment] also runs the
destructor of its left-hand operand, unless it's an uninitialized variable. If a
[struct] variable has been partially initialized, only its initialized fields
are dropped.
variable has been partially initialized, only its initialized fields are
dropped.

The destructor of a type consists of

Expand Down Expand Up @@ -63,10 +63,11 @@ 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");
core::mem::forget(partially_initialized.1);
}
```

Expand Down

0 comments on commit c85e5a7

Please sign in to comment.