summaryrefslogtreecommitdiffstats
path: root/library/core/src/panic.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:25:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:25:53 +0000
commit73e0a5b7696ea019ba35b89f38fc8e7b285d99cb (patch)
tree0d2e175af6f114cb50a675bec0bc76e12e1bceb4 /library/core/src/panic.rs
parentAdding upstream version 1.75.0+dfsg1. (diff)
downloadrustc-upstream.tar.xz
rustc-upstream.zip
Adding upstream version 1.76.0+dfsg1.upstream/1.76.0+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/core/src/panic.rs')
-rw-r--r--library/core/src/panic.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/library/core/src/panic.rs b/library/core/src/panic.rs
index a00fd322b..4ca5af1ea 100644
--- a/library/core/src/panic.rs
+++ b/library/core/src/panic.rs
@@ -47,7 +47,7 @@ pub macro panic_2015 {
#[allow_internal_unstable(core_panic, const_format_args)]
#[rustc_diagnostic_item = "core_panic_2021_macro"]
#[rustc_macro_transparency = "semitransparent"]
-#[cfg(any(bootstrap, feature = "panic_immediate_abort"))]
+#[cfg(feature = "panic_immediate_abort")]
pub macro panic_2021 {
() => (
$crate::panicking::panic("explicit panic")
@@ -75,7 +75,7 @@ pub macro panic_2021 {
)]
#[rustc_diagnostic_item = "core_panic_2021_macro"]
#[rustc_macro_transparency = "semitransparent"]
-#[cfg(not(any(bootstrap, feature = "panic_immediate_abort")))]
+#[cfg(not(feature = "panic_immediate_abort"))]
pub macro panic_2021 {
() => ({
// Create a function so that the argument for `track_caller`
@@ -139,6 +139,32 @@ pub macro unreachable_2021 {
),
}
+/// Asserts that a boolean expression is `true`, and perform a non-unwinding panic otherwise.
+///
+/// This macro is similar to `debug_assert!`, but is intended to be used in code that should not
+/// unwind. For example, checks in `_unchecked` functions that are intended for debugging but should
+/// not compromise unwind safety.
+#[doc(hidden)]
+#[unstable(feature = "core_panic", issue = "none")]
+#[allow_internal_unstable(core_panic, const_format_args)]
+#[rustc_macro_transparency = "semitransparent"]
+pub macro debug_assert_nounwind {
+ ($cond:expr $(,)?) => {
+ if $crate::cfg!(debug_assertions) {
+ if !$cond {
+ $crate::panicking::panic_nounwind($crate::concat!("assertion failed: ", $crate::stringify!($cond)));
+ }
+ }
+ },
+ ($cond:expr, $($arg:tt)+) => {
+ if $crate::cfg!(debug_assertions) {
+ if !$cond {
+ $crate::panicking::panic_nounwind_fmt($crate::const_format_args!($($arg)+), false);
+ }
+ }
+ },
+}
+
/// 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.