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
+2-3Lines changed: 2 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -426,19 +426,18 @@ let x = (&temp()).use_temp(); // ERROR
426
426
r[destructors.forget]
427
427
## Not running destructors
428
428
429
+
r[destructors.manually-preventing]
429
430
### Manually preventing destructors
430
431
431
-
r[destructors.manually-preventing]
432
432
[`std::mem::forget`] can be used to prevent the destructor of a variable from being run,
433
433
and [`std::mem::ManuallyDrop`] provides a wrapper to prevent a
434
434
variable or field from being dropped automatically.
435
435
436
436
> 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`.
437
437
> 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.
438
438
439
-
### Process termination without unwinding
440
-
441
439
r[destructors.process-termination]
440
+
### Process termination without unwinding
442
441
443
442
There are some ways to terminate the process without [unwinding], in which case
Copy file name to clipboardExpand all lines: src/panic.md
+4-8Lines changed: 4 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,5 @@
1
-
# Panic
2
-
3
1
r[panic]
2
+
# Panic
4
3
5
4
r[panic.intro]
6
5
Rust provides a mechanism to prevent a function from returning normally, and instead "panic," which is a response to an error condition that is typically not expected to be recoverable within the context in which the error is encountered.
@@ -17,9 +16,8 @@ There are also language features that provide a level of control over panic beha
17
16
> [!NOTE]
18
17
> The standard library provides the capability to explicitly panic via the [`panic!` macro][panic!].
19
18
20
-
## Unwinding
21
-
22
19
r[panic.unwind]
20
+
## Unwinding
23
21
24
22
r[panic.unwind.intro]
25
23
Panicking may either be recoverable or non-recoverable, though it can be configured (via `panic=abort`) to always be non-recoverable. (The converse is not true: `panic=unwind` does not guarantee that all panics are recoverable, only that panicking via the `panic!` macro and similar standard library mechanisms is recoverable.)
@@ -33,9 +31,8 @@ When panic recovery occurs, the runtime "unwinds" Rust frames, just as C++'s `th
33
31
> [!NOTE]
34
32
> The standard library provides two mechanisms for recovering from a panic, [`std::panic::catch_unwind`] (which enables recovery within the panicking thread) and [`std::thread::spawn`] (which automatically sets up panic recovery for the spawned thread so that other threads may continue running).
35
33
36
-
### Unwinding across FFI boundaries
37
-
38
34
r[panic.unwind.ffi]
35
+
### Unwinding across FFI boundaries
39
36
40
37
r[panic.unwind.ffi.intro]
41
38
It is possible to unwind across FFI boundaries using an [appropriate ABI declaration][unwind-abi]. While useful in certain cases, this creates unique opportunities for undefined behavior, especially when multiple language runtimes are involved.
@@ -58,9 +55,8 @@ Catching a foreign unwinding operation (such as a C++ exception) using [`std::pa
58
55
r[panic.unwind.ffi.dispose-panic]
59
56
There are currently no guarantees about the behavior that occurs when a foreign runtime attempts to dispose of, or rethrow, a Rust `panic` payload. In other words, an unwind originated from a Rust runtime must either lead to termination of the process or be caught by the same runtime.
60
57
61
-
## Panic runtimes
62
-
63
58
r[panic.runtime]
59
+
## Panic runtimes
64
60
65
61
The actual behavior and implementation of `panic!` is controlled by the _panic runtime_.
0 commit comments