You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/destructors.md
+22-1Lines changed: 22 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -268,7 +268,8 @@ Temporaries are also created to hold the result of operands to an expression
268
268
while the other operands are evaluated. The temporaries are associated to the
269
269
scope of the expression with that operand. Since the temporaries are moved from
270
270
once the expression is evaluated, dropping them has no effect unless one of the
271
-
operands to an expression breaks out of the expression, returns, or panics.
271
+
operands to an expression breaks out of the expression, returns, or
272
+
[panics][panic].
272
273
273
274
```rust
274
275
# structPrintOnDrop(&'staticstr);
@@ -419,6 +420,8 @@ let x = (&temp()).use_temp(); // ERROR
419
420
420
421
## Not running destructors
421
422
423
+
### `forget`
424
+
422
425
r[destructors.forget]
423
426
424
427
[`std::mem::forget`] can be used to prevent the destructor of a variable from being run,
@@ -428,6 +431,20 @@ variable or field from being dropped automatically.
428
431
> 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`.
429
432
> 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.
430
433
434
+
### Process termination without unwinding
435
+
436
+
There are some ways to terminate the process without [unwinding], in which case
437
+
destructors will not be run.
438
+
439
+
The standard library provides [`std::process::exit`] and
440
+
[`std::process::abort`] to do this explicitly. Additionally, if the
441
+
[panic-mode] is set to `abort`, panicking will always terminate the process
442
+
without destructors being run.
443
+
444
+
There is one additional case to be aware of: when a panic reaches a
445
+
[non-unwinding ABI boundary], either no destructors will run, or all
0 commit comments