Skip to content

Commit

Permalink
Update rules to be with headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jan 14, 2025
1 parent 550102b commit c63cdbc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/destructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,18 @@ 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.

> 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.
Expand Down
3 changes: 1 addition & 2 deletions src/items/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions src/linkage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions src/panic.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.)
Expand All @@ -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.
Expand All @@ -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_.

Expand Down

0 comments on commit c63cdbc

Please sign in to comment.