add core::panic::abort_unwind
This commit is contained in:
parent
23b04c0513
commit
de66d3aa2b
1 changed files with 30 additions and 0 deletions
|
@ -140,6 +140,36 @@ pub macro unreachable_2021 {
|
|||
),
|
||||
}
|
||||
|
||||
/// Invokes a closure, aborting if the closure unwinds.
|
||||
///
|
||||
/// When compiled with aborting panics, this function is effectively a no-op.
|
||||
/// With unwinding panics, an unwind results in another call into the panic
|
||||
/// hook followed by a process abort.
|
||||
///
|
||||
/// # Notes
|
||||
///
|
||||
/// Instead of using this function, code should attempt to support unwinding.
|
||||
/// Implementing [`Drop`] allows you to restore invariants uniformly in both
|
||||
/// return and unwind paths.
|
||||
///
|
||||
/// If an unwind can lead to logical issues but not soundness issues, you
|
||||
/// should allow the unwind. Opting out of [`UnwindSafe`] indicates to your
|
||||
/// consumers that they need to consider correctness in the face of unwinds.
|
||||
///
|
||||
/// If an unwind would be unsound, then this function should be used in order
|
||||
/// to prevent unwinds. However, note that `extern "C" fn` will automatically
|
||||
/// convert unwinds to aborts, so using this function isn't necessary for FFI.
|
||||
#[unstable(feature = "abort_unwind", issue = "130338")]
|
||||
pub fn abort_unwind<F: FnOnce() -> R, R>(f: F) -> R {
|
||||
// This attribute adds the "unwinding out of nounwind function" guard.
|
||||
#[rustc_nounwind]
|
||||
fn abort_unwind_inner<F: FnOnce() -> R, R>(f: F) -> R {
|
||||
f()
|
||||
}
|
||||
|
||||
abort_unwind_inner(f)
|
||||
}
|
||||
|
||||
/// An internal trait used by std to pass data from std to `panic_unwind` and
|
||||
/// other panic runtimes. Not intended to be stabilized any time soon, do not
|
||||
/// use.
|
||||
|
|
Loading…
Add table
Reference in a new issue