Skip to content

Commit bf703da

Browse files
committed
update catch_unwind doc comments to indicate that catching a foreign exception is UB
1 parent 176e545 commit bf703da

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

library/core/src/intrinsics.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,9 @@ extern "rust-intrinsic" {
23732373
pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
23742374

23752375
/// Rust's "try catch" construct for unwinding. Invokes the function pointer `try_fn` with the
2376-
/// data pointer `data`, and calls `catch_fn` if unwinding occurs while `try_fn` runs.
2376+
/// data pointer `data`, and calls `catch_fn` if a panic occurs while `try_fn` runs. (It is
2377+
/// undefined behavior to catch an unwinding operation from another language with this
2378+
/// function.)
23772379
///
23782380
/// `catch_fn` must not unwind.
23792381
///

library/std/src/panic.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,18 @@ where
311311
///
312312
/// # Notes
313313
///
314-
/// Note that this function **might not catch all panics** in Rust. A panic in
315-
/// Rust is not always implemented via unwinding, but can be implemented by
316-
/// aborting the process as well. This function *only* catches unwinding panics,
317-
/// not those that abort the process.
318-
///
319-
/// Note that if a custom panic hook has been set, it will be invoked before
320-
/// the panic is caught, before unwinding.
321-
///
322-
/// Also note that unwinding into Rust code with a foreign exception (e.g.
323-
/// an exception thrown from C++ code) is undefined behavior.
314+
/// This function **might not catch all panics** in Rust. A panic in Rust is not
315+
/// always implemented via unwinding, but can be implemented by aborting the
316+
/// process as well. This function *only* catches unwinding panics, not those
317+
/// that abort the process.
318+
///
319+
/// If a custom panic hook has been set, it will be invoked before the panic is
320+
/// caught, before unwinding.
321+
///
322+
/// Although unwinding into Rust code with a foreign exception (e.g. an
323+
/// exception thrown from C++ code) via an appropriate ABI (e.g. `"C-unwind"`)
324+
/// is permitted, catching such an exception using this function is undefined
325+
/// behavior.
324326
///
325327
/// Finally, be **careful in how you drop the result of this function**.
326328
/// If it is `Err`, it contains the panic payload, and dropping that may in turn panic!

0 commit comments

Comments
 (0)