diff --git a/src/destructors.md b/src/destructors.md index ff4f969d4..301fc24a5 100644 --- a/src/destructors.md +++ b/src/destructors.md @@ -426,9 +426,9 @@ let x = (&temp()).use_temp(); // ERROR r[destructors.forget] ## Not running destructors +r[destructors.manually-preventing] ### Manually preventing destructors -r[destructors.manually-preventing] [`std::mem::forget`] can be used to prevent the destructor of a variable from being run, and [`std::mem::ManuallyDrop`] provides a wrapper to prevent a variable or field from being dropped automatically. @@ -436,9 +436,8 @@ variable or field from being dropped automatically. > 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`. > 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. -### Process termination without unwinding - r[destructors.process-termination] +### Process termination without unwinding There are some ways to terminate the process without [unwinding], in which case destructors will not be run. diff --git a/src/items/functions.md b/src/items/functions.md index 020ecb7c5..a9f6316d2 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -253,9 +253,8 @@ extern "C" fn new_i32() -> i32 { 0 } let fptr: extern "C" fn() -> i32 = new_i32; ``` -### Unwinding - r[items.fn.extern.unwind] +### Unwinding r[items.fn.extern.unwind.intro] Most ABI strings come in two variants, one with an `-unwind` suffix and one without. diff --git a/src/linkage.md b/src/linkage.md index dba494357..f17560b87 100644 --- a/src/linkage.md +++ b/src/linkage.md @@ -275,9 +275,8 @@ Passing `rlib`s directly into your foreign linker is currently unsupported. > Rust code compiled or linked with a different instance of the Rust runtime counts as a > "foreign code" for the purpose of this section. -### Prohibited linkage and unwinding - r[link.unwinding] +### Prohibited linkage and unwinding r[link.unwinding.consistency] If you are *not* using `rustc` to link Rust files, you must take care to ensure that unwinding is diff --git a/src/panic.md b/src/panic.md index a752e306d..b0c16f477 100644 --- a/src/panic.md +++ b/src/panic.md @@ -1,6 +1,5 @@ -# Panic - r[panic] +# Panic r[panic.intro] 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 > [!NOTE] > The standard library provides the capability to explicitly panic via the [`panic!` macro][panic!]. -## Unwinding - r[panic.unwind] +## Unwinding r[panic.unwind.intro] 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 > [!NOTE] > 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). -### Unwinding across FFI boundaries - r[panic.unwind.ffi] +### Unwinding across FFI boundaries r[panic.unwind.ffi.intro] 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 r[panic.unwind.ffi.dispose-panic] 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. -## Panic runtimes - r[panic.runtime] +## Panic runtimes The actual behavior and implementation of `panic!` is controlled by the _panic runtime_.