]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/panic.rs
Auto merge of #30917 - arthurprs:bs_bounds_check, r=alexcrichton
[rust.git] / src / libstd / panic.rs
index 76d9c194b452001b81a6b42037b98571bf95fb14..3677bd27b16194f90fe6b37f8439c9735331647b 100644 (file)
@@ -13,6 +13,8 @@
 #![unstable(feature = "std_panic", reason = "awaiting feedback",
             issue = "27719")]
 
+use any::Any;
+use boxed::Box;
 use cell::UnsafeCell;
 use ops::{Deref, DerefMut};
 use ptr::{Unique, Shared};
@@ -134,7 +136,7 @@ pub trait RefRecoverSafe {}
 ///
 /// let mut variable = 4;
 ///
-/// // This code will not compile becuause the closure captures `&mut variable`
+/// // This code will not compile because the closure captures `&mut variable`
 /// // which is not considered panic safe by default.
 ///
 /// // panic::recover(|| {
@@ -259,3 +261,28 @@ pub fn recover<F: FnOnce() -> R + RecoverSafe, R>(f: F) -> Result<R> {
     }
     Ok(result.unwrap())
 }
+
+/// Triggers a panic without invoking the panic handler.
+///
+/// This is designed to be used in conjunction with `recover` to, for example,
+/// carry a panic across a layer of C code.
+///
+/// # Examples
+///
+/// ```should_panic
+/// #![feature(std_panic, recover, panic_propagate)]
+///
+/// use std::panic;
+///
+/// let result = panic::recover(|| {
+///     panic!("oh no!");
+/// });
+///
+/// if let Err(err) = result {
+///     panic::propagate(err);
+/// }
+/// ```
+#[unstable(feature = "panic_propagate", reason = "awaiting feedback", issue = "30752")]
+pub fn propagate(payload: Box<Any + Send>) -> ! {
+    unwind::rust_panic(payload)
+}