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)]
24#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
25#[allow_internal_unstable(panic_internals, const_format_args)]
26#[rustc_diagnostic_item = "core_panic_2015_macro"]
27#[rustc_macro_transparency = "semitransparent"]
28#[cfg(feature = "ferrocene_certified_runtime")]
29pub macro panic_2015($($t:tt)*) {{ $crate::panicking::panic("explicit panic") }}
30
31#[doc(hidden)]
32#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
33#[allow_internal_unstable(panic_internals, const_format_args)]
34#[rustc_diagnostic_item = "core_panic_2015_macro"]
35#[rustc_macro_transparency = "semitransparent"]
36#[cfg(not(feature = "ferrocene_certified_runtime"))]
37pub macro panic_2015 {
38 () => (
39 $crate::panicking::panic("explicit panic")
40 ),
41 ($msg:literal $(,)?) => (
42 $crate::panicking::panic($msg)
43 ),
44 ($msg:expr $(,)?) => ({
46 $crate::panicking::panic_str_2015($msg);
47 }),
48 ("{}", $arg:expr $(,)?) => ({
50 $crate::panicking::panic_display(&$arg);
51 }),
52 ($fmt:expr, $($arg:tt)+) => ({
53 $crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+));
56 }),
57}
58
59#[doc(hidden)]
61#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
62#[allow_internal_unstable(panic_internals, const_format_args)]
63#[rustc_diagnostic_item = "core_panic_2021_macro"]
64#[rustc_macro_transparency = "semitransparent"]
65#[cfg(feature = "ferrocene_certified_runtime")]
66pub macro panic_2021($($t:tt)*) {{ $crate::panicking::panic("explicit panic") }}
67
68#[doc(hidden)]
69#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
70#[allow_internal_unstable(panic_internals, const_format_args)]
71#[rustc_diagnostic_item = "core_panic_2021_macro"]
72#[rustc_macro_transparency = "semitransparent"]
73#[cfg(not(feature = "ferrocene_certified_runtime"))]
74pub macro panic_2021 {
75 () => (
76 $crate::panicking::panic("explicit panic")
77 ),
78 ("{}", $arg:expr $(,)?) => ({
80 $crate::panicking::panic_display(&$arg);
81 }),
82 ($($t:tt)+) => ({
83 $crate::panicking::panic_fmt($crate::const_format_args!($($t)+));
86 }),
87}
88
89#[doc(hidden)]
91#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
92#[allow_internal_unstable(panic_internals)]
93#[rustc_diagnostic_item = "unreachable_2015_macro"]
94#[rustc_macro_transparency = "semitransparent"]
95#[cfg(feature = "ferrocene_certified_runtime")]
96pub macro unreachable_2015 {
97 ($($t:tt)*) => (
98 $crate::panicking::panic("internal error: entered unreachable code")
99 ),
100}
101
102#[doc(hidden)]
103#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
104#[allow_internal_unstable(panic_internals)]
105#[rustc_diagnostic_item = "unreachable_2015_macro"]
106#[rustc_macro_transparency = "semitransparent"]
107#[cfg(not(feature = "ferrocene_certified_runtime"))]
108pub macro unreachable_2015 {
109 () => (
110 $crate::panicking::panic("internal error: entered unreachable code")
111 ),
112 ($msg:expr $(,)?) => ({
115 $crate::panicking::unreachable_display(&$msg);
116 }),
117 ($fmt:expr, $($arg:tt)*) => (
118 $crate::panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
119 ),
120}
121
122#[doc(hidden)]
124#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
125#[allow_internal_unstable(panic_internals)]
126#[rustc_macro_transparency = "semitransparent"]
127#[cfg(feature = "ferrocene_certified_runtime")]
128pub macro unreachable_2021 {
129 ($($t:tt)*) => (
130 $crate::panicking::panic("internal error: entered unreachable code")
131 ),
132}
133
134#[doc(hidden)]
135#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
136#[allow_internal_unstable(panic_internals)]
137#[rustc_macro_transparency = "semitransparent"]
138#[cfg(not(feature = "ferrocene_certified_runtime"))]
139pub macro unreachable_2021 {
140 () => (
141 $crate::panicking::panic("internal error: entered unreachable code")
142 ),
143 ($($t:tt)+) => (
144 $crate::panic!("internal error: entered unreachable code: {}", $crate::format_args!($($t)+))
145 ),
146}
147
148#[unstable(feature = "abort_unwind", issue = "130338")]
168#[rustc_nounwind]
169#[cfg(not(feature = "ferrocene_subset"))]
170pub fn abort_unwind<F: FnOnce() -> R, R>(f: F) -> R {
171 f()
172}
173
174#[unstable(feature = "std_internals", issue = "none")]
178#[doc(hidden)]
179#[cfg(not(feature = "ferrocene_subset"))]
180pub unsafe trait PanicPayload: crate::fmt::Display {
181 fn take_box(&mut self) -> *mut (dyn Any + Send);
190
191 fn get(&mut self) -> &(dyn Any + Send);
193
194 fn as_str(&mut self) -> Option<&str> {
196 None
197 }
198}
199
200#[unstable(feature = "panic_internals", issue = "none")]
209#[doc(hidden)]
210pub macro const_panic {
211 ($const_msg:literal, $runtime_msg:literal, $($arg:ident : $ty:ty = $val:expr),* $(,)?) => {{
212 #[rustc_allow_const_fn_unstable(const_eval_select)]
216 #[inline(always)] #[track_caller]
218 #[cfg_attr(feature = "ferrocene_certified_runtime", expect(unused_variables))]
220 const fn do_panic($($arg: $ty),*) -> ! {
221 $crate::intrinsics::const_eval_select!(
222 @capture { $($arg: $ty = $arg),* } -> !:
223 #[noinline]
224 if const #[track_caller] #[inline] { $crate::panic!($const_msg)
226 } else #[track_caller] { $crate::panic!($runtime_msg)
228 }
229 )
230 }
231
232 do_panic($($val),*)
233 }},
234 ($const_msg:literal, $runtime_msg:literal, $($arg:ident : $ty:ty),* $(,)?) => {
237 $crate::panic::const_panic!(
238 $const_msg,
239 $runtime_msg,
240 $($arg: $ty = $arg),*
241 )
242 },
243}
244
245#[unstable(feature = "panic_internals", issue = "none")]
249#[doc(hidden)]
250pub macro const_assert {
251 ($condition: expr, $const_msg:literal, $runtime_msg:literal, $($arg:tt)*) => {{
252 if !$crate::intrinsics::likely($condition) {
253 $crate::panic::const_panic!($const_msg, $runtime_msg, $($arg)*)
254 }
255 }}
256}