Skip to content

Commit 352c440

Browse files
authored
Try to clarify destructor not being run scenario.
This is being discussed in https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Guarantees.20around.20Drop.20.28.2390752.29.
1 parent 953829f commit 352c440

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/destructors.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,14 @@ 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 `forget` or other means is safe in Rust
353+
> even if it has a type that isn't `'static`. This means that publicly exposed APIs cannot
354+
> rely on destructor being run for soundness.
355+
352356
[Assignment]: expressions/operator-expr.md#assignment-expressions
353357
[binding modes]: patterns.md#binding-modes
354358
[closure]: types/closure.md
@@ -395,4 +399,5 @@ variable or field from being dropped automatically.
395399

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

0 commit comments

Comments
 (0)