]> git.proxmox.com Git - rustc.git/blobdiff - src/doc/reference/src/destructors.md
New upstream version 1.61.0+dfsg1
[rustc.git] / src / doc / reference / src / destructors.md
index cf7ab0aca21eaaf82f3dcbde86899c3470dabd0e..6d616b3e77e3ab3a32d5a380ae5d40d5d3af36ed 100644 (file)
@@ -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
@@ -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