File tree 1 file changed +7
-2
lines changed
1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -345,10 +345,14 @@ let x = (&temp()).use_temp(); // ERROR
345
345
346
346
## Not running destructors
347
347
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
350
350
variable or field from being dropped automatically.
351
351
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
+
352
356
[ Assignment ] : expressions/operator-expr.md#assignment-expressions
353
357
[ binding modes ] : patterns.md#binding-modes
354
358
[ closure ] : types/closure.md
@@ -395,4 +399,5 @@ variable or field from being dropped automatically.
395
399
396
400
[ `<T as std::ops::Drop>::drop` ] : ../std/ops/trait.Drop.html#tymethod.drop
397
401
[ `std::ptr::drop_in_place` ] : ../std/ptr/fn.drop_in_place.html
402
+ [ `std::mem::forget` ] : ../std/mem/fn.forget.html
398
403
[ `std::mem::ManuallyDrop` ] : ../std/mem/struct.ManuallyDrop.html
You can’t perform that action at this time.
0 commit comments