1#![stable(feature = "core_panic_info", since = "1.41.0")]
4
5mod location;
6mod panic_info;
7#[cfg(not(feature = "ferrocene_subset"))]
8mod unwind_safe;
9
10#[stable(feature = "panic_hooks", since = "1.10.0")]
11pub use self::location::Location;
12#[stable(feature = "panic_hooks", since = "1.10.0")]
13pub use self::panic_info::PanicInfo;
14#[stable(feature = "panic_info_message", since = "1.81.0")]
15pub use self::panic_info::PanicMessage;
16#[stable(feature = "catch_unwind", since = "1.9.0")]
17#[cfg(not(feature = "ferrocene_subset"))]
18pub use self::unwind_safe::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe};
19#[cfg(not(feature = "ferrocene_subset"))]
20use crate::any::Any;
21
22#[doc(hidden)]
23#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
24#[allow_internal_unstable(panic_internals, const_format_args)]
25#[rustc_diagnostic_item = "core_panic_2015_macro"]
26#[rustc_macro_transparency = "semiopaque"]
27pub macro panic_2015 {
28 () => (
29 $crate::panicking::panic("explicit panic")
30 ),
31 ($msg:literal $(,)?) => (
32 $crate::panicking::panic($msg)
33 ),
34 ($msg:expr $(,)?) => ({
36 $crate::panicking::panic_str_2015($msg);
37 }),
38 ("{}", $arg:expr $(,)?) => ({
40 $crate::panicking::panic_display(&$arg);
41 }),
42 ($fmt:expr, $($arg:tt)+) => ({
43 $crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+));
46 }),
47}
48
49#[doc(hidden)]
50#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
51#[allow_internal_unstable(panic_internals, const_format_args)]
52#[rustc_diagnostic_item = "core_panic_2021_macro"]
53#[rustc_macro_transparency = "semiopaque"]
54pub macro panic_2021 {
55 () => (
56 $crate::panicking::panic("explicit panic")
57 ),
58 ("{}", $arg:expr $(,)?) => ({
60 $crate::panicking::panic_display(&$arg);
61 }),
62 ($($t:tt)+) => ({
63 $crate::panicking::panic_fmt($crate::const_format_args!($($t)+));
66 }),
67}
68
69#[doc(hidden)]
70#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
71#[allow_internal_unstable(panic_internals)]
72#[rustc_diagnostic_item = "unreachable_2015_macro"]
73#[rustc_macro_transparency = "semiopaque"]
74pub macro unreachable_2015 {
75 () => (
76 $crate::panicking::panic("internal error: entered unreachable code")
77 ),
78 ($msg:expr $(,)?) => ({
81 $crate::panicking::unreachable_display(&$msg);
82 }),
83 ($fmt:expr, $($arg:tt)*) => (
84 $crate::panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
85 ),
86}
87
88#[doc(hidden)]
89#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
90#[allow_internal_unstable(panic_internals)]
91#[rustc_macro_transparency = "semiopaque"]
92pub macro unreachable_2021 {
93 () => (
94 $crate::panicking::panic("internal error: entered unreachable code")
95 ),
96 ($($t:tt)+) => (
97 $crate::panic!("internal error: entered unreachable code: {}", $crate::format_args!($($t)+))
98 ),
99}
100
101#[unstable(feature = "abort_unwind", issue = "130338")]
121#[rustc_nounwind]
122#[cfg(not(feature = "ferrocene_subset"))]
123pub fn abort_unwind<F: FnOnce() -> R, R>(f: F) -> R {
124 f()
125}
126
127#[unstable(feature = "std_internals", issue = "none")]
131#[doc(hidden)]
132#[cfg(not(feature = "ferrocene_subset"))]
133pub unsafe trait PanicPayload: crate::fmt::Display {
134 fn take_box(&mut self) -> *mut (dyn Any + Send);
143
144 fn get(&mut self) -> &(dyn Any + Send);
146
147 fn as_str(&mut self) -> Option<&str> {
149 None
150 }
151}
152
153#[unstable(feature = "panic_internals", issue = "none")]
162#[doc(hidden)]
163pub macro const_panic {
164 ($const_msg:literal, $runtime_msg:literal, $($arg:ident : $ty:ty = $val:expr),* $(,)?) => {{
165 #[rustc_allow_const_fn_unstable(const_eval_select)]
169 #[inline(always)] #[track_caller]
171 const fn do_panic($($arg: $ty),*) -> ! {
172 $crate::intrinsics::const_eval_select!(
173 @capture { $($arg: $ty = $arg),* } -> !:
174 if const #[track_caller] {
175 $crate::panic!($const_msg)
176 } else #[track_caller] {
177 $crate::panic!($runtime_msg)
178 }
179 )
180 }
181
182 do_panic($($val),*)
183 }},
184 ($const_msg:literal, $runtime_msg:literal, $($arg:ident : $ty:ty),* $(,)?) => {
187 $crate::panic::const_panic!(
188 $const_msg,
189 $runtime_msg,
190 $($arg: $ty = $arg),*
191 )
192 },
193}
194
195#[unstable(feature = "panic_internals", issue = "none")]
199#[doc(hidden)]
200pub macro const_assert {
201 ($condition: expr, $const_msg:literal, $runtime_msg:literal, $($arg:tt)*) => {{
202 if !($condition) {
203 $crate::panic::const_panic!($const_msg, $runtime_msg, $($arg)*)
204 }
205 }}
206}