Skip to content

Commit f576209

Browse files
committed
Move panic runtimes towards the top of the chapter
The intent here is to introduce higher-level concepts first, and then go into the details of unwinding.
1 parent 33a16de commit f576209

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/panic.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ There are also language features that provide a level of control over panic beha
1616
> [!NOTE]
1717
> The standard library provides the capability to explicitly panic via the [`panic!` macro][panic!].
1818
19+
r[panic.runtime]
20+
## Panic runtimes
21+
22+
The actual behavior and implementation of `panic!` is controlled by the _panic runtime_.
23+
24+
> [!NOTE]
25+
> The Rust standard library provides two panic runtimes: `panic_unwind` (which unwinds the stack and is potentially recoverable) and `panic_abort` (which aborts the process and is non-recoverable). The default runtime depends on the target platform, but is generally `panic_unwind` on platforms with native support for C++ exceptions.
26+
27+
> [!NOTE]
28+
> When compiling code that is guaranteed to be linked to a non-recoverable panic runtime, the optimizer may assume that unwinding across Rust frames is impossible, which can result in both code-size and runtime speed improvements.
29+
30+
See also the [`panic_handler` attribute](runtime.md#the-panic_handler-attribute) which can be used to change the behavior of panics.
31+
1932
r[panic.unwind]
2033
## Unwinding
2134

@@ -55,19 +68,6 @@ Catching a foreign unwinding operation (such as a C++ exception) using [`std::pa
5568
r[panic.unwind.ffi.dispose-panic]
5669
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.
5770

58-
r[panic.runtime]
59-
## Panic runtimes
60-
61-
The actual behavior and implementation of `panic!` is controlled by the _panic runtime_.
62-
63-
> [!NOTE]
64-
> The Rust standard library provides two panic runtimes: `panic_unwind` (which unwinds the stack and is potentially recoverable) and `panic_abort` (which aborts the process and is non-recoverable). The default runtime depends on the target platform, but is generally `panic_unwind` on platforms with native support for C++ exceptions.
65-
66-
> [!NOTE]
67-
> When compiling code that is guaranteed to be linked to a non-recoverable panic runtime, the optimizer may assume that unwinding across Rust frames is impossible, which can result in both code-size and runtime speed improvements.
68-
69-
See also the [`panic_handler` attribute](runtime.md#the-panic_handler-attribute) which can be used to change the behavior of panics.
70-
7171
[array indexing]: expressions/array-expr.md#array-and-slice-indexing-expressions
7272
[destructors]: destructors.md
7373
[runtime]: runtime.md

0 commit comments

Comments
 (0)