Skip to content

Commit

Permalink
Merge pull request #1107 from nbdd0121/patch-1
Browse files Browse the repository at this point in the history
Try to clarify destructor not being run scenario.
  • Loading branch information
ehuss committed Mar 14, 2022
2 parents f74bb08 + f1a8b53 commit 71cdfb9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/destructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,13 @@ let x = (&temp()).use_temp(); // ERROR

## Not running destructors

Not running destructors in Rust is safe even if it has a type that isn't
`'static`. [`std::mem::ManuallyDrop`] provides a wrapper to prevent a
[`std::mem::forget`] can be used to prevent the destructor of a variable from being run,
and [`std::mem::ManuallyDrop`] provides a wrapper to prevent a
variable or field from being dropped automatically.

> Note: Preventing a destructor from being run via [`std::mem::forget`] or other means is safe even if it has a type that isn't `'static`.
> Besides the places where destructors are guaranteed to run as defined by this document, types may *not* safely rely on a destructor being run for soundness.
[Assignment]: expressions/operator-expr.md#assignment-expressions
[binding modes]: patterns.md#binding-modes
[closure]: types/closure.md
Expand Down Expand Up @@ -395,4 +398,5 @@ variable or field from being dropped automatically.

[`<T as std::ops::Drop>::drop`]: ../std/ops/trait.Drop.html#tymethod.drop
[`std::ptr::drop_in_place`]: ../std/ptr/fn.drop_in_place.html
[`std::mem::forget`]: ../std/mem/fn.forget.html
[`std::mem::ManuallyDrop`]: ../std/mem/struct.ManuallyDrop.html

0 comments on commit 71cdfb9

Please sign in to comment.