Skip to content

Commit ce91d15

Browse files
committed
update catch_unwind doc comments to indicate that catching a foreign exception is UB
1 parent 2cbbe8b commit ce91d15

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
@@ -2392,7 +2392,9 @@ extern "rust-intrinsic" {
23922392
pub fn variant_count<T>() -> usize;
23932393

23942394
/// Rust's "try catch" construct for unwinding. Invokes the function pointer `try_fn` with the
2395-
/// data pointer `data`, and calls `catch_fn` if unwinding occurs while `try_fn` runs.
2395+
/// data pointer `data`, and calls `catch_fn` if a panic occurs while `try_fn` runs. (It is
2396+
/// undefined behavior to catch an unwinding operation from another language with this
2397+
/// function.)
23962398
///
23972399
/// `catch_fn` must not unwind.
23982400
///

library/std/src/panic.rs

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

0 commit comments

Comments
 (0)