Skip to content

Commit 71cdfb9

Browse files
authored
Merge pull request #1107 from nbdd0121/patch-1
Try to clarify destructor not being run scenario.
2 parents f74bb08 + f1a8b53 commit 71cdfb9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/destructors.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,13 @@ let x = (&temp()).use_temp(); // ERROR
345345

346346
## Not running destructors
347347

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

352+
> 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`.
353+
> 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.
354+
352355
[Assignment]: expressions/operator-expr.md#assignment-expressions
353356
[binding modes]: patterns.md#binding-modes
354357
[closure]: types/closure.md
@@ -395,4 +398,5 @@ variable or field from being dropped automatically.
395398

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

0 commit comments

Comments
 (0)