about summary refs log tree commit diff
path: root/library/core/src/panic
diff options
context:
space:
mode:
authorAmanieu d'Antras <amanieu@gmail.com>2021-12-19 00:43:46 +0100
committerAmanieu d'Antras <amanieu@gmail.com>2022-01-17 00:39:28 +0000
commit528c4f9158ead3df8cecb51663db50e711fec377 (patch)
tree8a22999a5a1f57297f3d1e0d091b5cf91209dd94 /library/core/src/panic
parentbd3cb52565faab2755ff1bdb54d88bc91f47b4b9 (diff)
Add PanicInfo::can_unwind which indicates whether a panic handler is
allowed to trigger unwinding.
Diffstat (limited to 'library/core/src/panic')
-rw-r--r--library/core/src/panic/panic_info.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/library/core/src/panic/panic_info.rs b/library/core/src/panic/panic_info.rs
index d8e421df5de..405224f8fb0 100644
--- a/library/core/src/panic/panic_info.rs
+++ b/library/core/src/panic/panic_info.rs
@@ -31,6 +31,7 @@ pub struct PanicInfo<'a> {
     payload: &'a (dyn Any + Send),
     message: Option<&'a fmt::Arguments<'a>>,
     location: &'a Location<'a>,
+    can_unwind: bool,
 }
 
 impl<'a> PanicInfo<'a> {
@@ -44,9 +45,10 @@ impl<'a> PanicInfo<'a> {
     pub fn internal_constructor(
         message: Option<&'a fmt::Arguments<'a>>,
         location: &'a Location<'a>,
+        can_unwind: bool,
     ) -> Self {
         struct NoPayload;
-        PanicInfo { location, message, payload: &NoPayload }
+        PanicInfo { location, message, payload: &NoPayload, can_unwind }
     }
 
     #[unstable(
@@ -127,6 +129,18 @@ impl<'a> PanicInfo<'a> {
         // deal with that case in std::panicking::default_hook and core::panicking::panic_fmt.
         Some(&self.location)
     }
+
+    /// Returns whether the panic handler is allowed to unwind the stack from
+    /// the point where the panic occurred.
+    ///
+    /// This is true for most kinds of panics with the exception of panics
+    /// caused by trying to unwind out of a `Drop` implementation or a function
+    /// whose ABI does not support unwinding.
+    #[must_use]
+    #[unstable(feature = "panic_can_unwind", issue = "92988")]
+    pub fn can_unwind(&self) -> bool {
+        self.can_unwind
+    }
 }
 
 #[stable(feature = "panic_hook_display", since = "1.26.0")]