1#![stable(feature = "core_panic_info", since = "1.41.0")]
4
5mod location;
6mod panic_info;
7mod unwind_safe;
8
9#[stable(feature = "panic_hooks", since = "1.10.0")]
10pub use self::location::Location;
11#[stable(feature = "panic_hooks", since = "1.10.0")]
12pub use self::panic_info::PanicInfo;
13#[stable(feature = "panic_info_message", since = "1.81.0")]
14pub use self::panic_info::PanicMessage;
15#[stable(feature = "catch_unwind", since = "1.9.0")]
16pub use self::unwind_safe::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe};
17use crate::any::Any;
18
19#[doc(hidden)]
20#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
21#[allow_internal_unstable(panic_internals, const_format_args)]
22#[rustc_diagnostic_item = "core_panic_2015_macro"]
23#[rustc_macro_transparency = "semitransparent"]
24pub macro panic_2015 {
25 () => (
26 $crate::panicking::panic("explicit panic")
27 ),
28 ($msg:literal $(,)?) => (
29 $crate::panicking::panic($msg)
30 ),
31 ($msg:expr $(,)?) => ({
33 $crate::panicking::panic_str_2015($msg);
34 }),
35 ("{}", $arg:expr $(,)?) => ({
37 $crate::panicking::panic_display(&$arg);
38 }),
39 ($fmt:expr, $($arg:tt)+) => ({
40 $crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+));
43 }),
44}
45
46#[doc(hidden)]
47#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
48#[allow_internal_unstable(panic_internals, const_format_args)]
49#[rustc_diagnostic_item = "core_panic_2021_macro"]
50#[rustc_macro_transparency = "semitransparent"]
51pub macro panic_2021 {
52 () => (
53 $crate::panicking::panic("explicit panic")
54 ),
55 ("{}", $arg:expr $(,)?) => ({
57 $crate::panicking::panic_display(&$arg);
58 }),
59 ($($t:tt)+) => ({
60 $crate::panicking::panic_fmt($crate::const_format_args!($($t)+));
63 }),
64}
65
66#[doc(hidden)]
67#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
68#[allow_internal_unstable(panic_internals)]
69#[rustc_diagnostic_item = "unreachable_2015_macro"]
70#[rustc_macro_transparency = "semitransparent"]
71pub macro unreachable_2015 {
72 () => (
73 $crate::panicking::panic("internal error: entered unreachable code")
74 ),
75 ($msg:expr $(,)?) => ({
78 $crate::panicking::unreachable_display(&$msg);
79 }),
80 ($fmt:expr, $($arg:tt)*) => (
81 $crate::panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
82 ),
83}
84
85#[doc(hidden)]
86#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
87#[allow_internal_unstable(panic_internals)]
88#[rustc_macro_transparency = "semitransparent"]
89pub macro unreachable_2021 {
90 () => (
91 $crate::panicking::panic("internal error: entered unreachable code")
92 ),
93 ($($t:tt)+) => (
94 $crate::panic!("internal error: entered unreachable code: {}", $crate::format_args!($($t)+))
95 ),
96}
97
98#[unstable(feature = "abort_unwind", issue = "130338")]
118#[rustc_nounwind]
119pub fn abort_unwind<F: FnOnce() -> R, R>(f: F) -> R {
120 f()
121}
122
123#[unstable(feature = "std_internals", issue = "none")]
127#[doc(hidden)]
128pub unsafe trait PanicPayload: crate::fmt::Display {
129 fn take_box(&mut self) -> *mut (dyn Any + Send);
138
139 fn get(&mut self) -> &(dyn Any + Send);
141
142 fn as_str(&mut self) -> Option<&str> {
144 None
145 }
146}
147
148#[unstable(feature = "panic_internals", issue = "none")]
157#[doc(hidden)]
158pub macro const_panic {
159 ($const_msg:literal, $runtime_msg:literal, $($arg:ident : $ty:ty = $val:expr),* $(,)?) => {{
160 #[rustc_allow_const_fn_unstable(const_eval_select)]
164 #[inline(always)] #[track_caller]
166 const fn do_panic($($arg: $ty),*) -> ! {
167 $crate::intrinsics::const_eval_select!(
168 @capture { $($arg: $ty = $arg),* } -> !:
169 #[noinline]
170 if const #[track_caller] #[inline] { $crate::panic!($const_msg)
172 } else #[track_caller] { $crate::panic!($runtime_msg)
174 }
175 )
176 }
177
178 do_panic($($val),*)
179 }},
180 ($const_msg:literal, $runtime_msg:literal, $($arg:ident : $ty:ty),* $(,)?) => {
183 $crate::panic::const_panic!(
184 $const_msg,
185 $runtime_msg,
186 $($arg: $ty = $arg),*
187 )
188 },
189}
190
191#[unstable(feature = "panic_internals", issue = "none")]
195#[doc(hidden)]
196pub macro const_assert {
197 ($condition: expr, $const_msg:literal, $runtime_msg:literal, $($arg:tt)*) => {{
198 if !$crate::intrinsics::likely($condition) {
199 $crate::panic::const_panic!($const_msg, $runtime_msg, $($arg)*)
200 }
201 }}
202}