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};
17
18#[doc(hidden)]
19#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
20#[allow_internal_unstable(panic_internals, const_format_args)]
21#[rustc_diagnostic_item = "core_panic_2015_macro"]
22#[rustc_macro_transparency = "semiopaque"]
23pub macro panic_2015 {
24 () => (
25 $crate::panicking::panic_default_msg()
26 ),
27 ($msg:literal $(,)?) => (
28 $crate::panicking::panic($msg)
29 ),
30 ($msg:expr $(,)?) => ({
32 $crate::panicking::panic_str_2015($msg);
33 }),
34 ("{}", $arg:expr $(,)?) => ({
36 $crate::panicking::panic_display(&$arg);
37 }),
38 ($fmt:expr, $($arg:tt)+) => ({
39 $crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+));
42 }),
43}
44
45#[doc(hidden)]
46#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
47#[allow_internal_unstable(panic_internals, const_format_args)]
48#[rustc_diagnostic_item = "core_panic_2021_macro"]
49#[rustc_macro_transparency = "semiopaque"]
50pub macro panic_2021 {
51 () => (
52 $crate::panicking::panic_default_msg()
53 ),
54 ("{}", $arg:expr $(,)?) => ({
56 $crate::panicking::panic_display(&$arg);
57 }),
58 ($($t:tt)+) => ({
59 $crate::panicking::panic_fmt($crate::const_format_args!($($t)+));
62 }),
63}
64
65#[doc(hidden)]
66#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
67#[allow_internal_unstable(panic_internals)]
68#[rustc_diagnostic_item = "unreachable_2015_macro"]
69#[rustc_macro_transparency = "semiopaque"]
70pub macro unreachable_2015 {
71 () => (
72 $crate::panicking::unreachable_default_msg()
73 ),
74 ($msg:expr $(,)?) => ({
77 $crate::panicking::unreachable_display(&$msg);
78 }),
79 ($fmt:expr, $($arg:tt)*) => (
80 $crate::panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
81 ),
82}
83
84#[doc(hidden)]
85#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
86#[allow_internal_unstable(panic_internals)]
87#[rustc_macro_transparency = "semiopaque"]
88pub macro unreachable_2021 {
89 () => (
90 $crate::panicking::unreachable_default_msg()
91 ),
92 ($($t:tt)+) => (
93 $crate::panic!("internal error: entered unreachable code: {}", $crate::format_args!($($t)+))
94 ),
95}
96
97#[unstable(feature = "abort_unwind", issue = "130338")]
118#[rustc_nounwind] pub fn abort_on_unwind<F: FnOnce() -> R, R>(f: F) -> R {
120 f()
121}
122
123#[unstable(feature = "panic_internals", issue = "none")]
132#[doc(hidden)]
133pub macro const_panic {
134 ($const_msg:literal, $runtime_msg:literal, $($arg:ident : $ty:ty = $val:expr),* $(,)?) => {{
135 #[rustc_allow_const_fn_unstable(const_eval_select)]
139 #[inline(always)] #[track_caller]
141 #[ferrocene::prevalidated]
142 const fn do_panic($($arg: $ty),*) -> ! {
143 $crate::intrinsics::const_eval_select!(
144 @capture { $($arg: $ty = $arg),* } -> !:
145 if const #[track_caller] {
146 $crate::panic!($const_msg)
147 } else #[track_caller] {
148 $crate::panic!($runtime_msg)
149 }
150 )
151 }
152
153 do_panic($($val),*)
154 }},
155 ($const_msg:literal, $runtime_msg:literal, $($arg:ident : $ty:ty),* $(,)?) => {
158 $crate::panic::const_panic!(
159 $const_msg,
160 $runtime_msg,
161 $($arg: $ty = $arg),*
162 )
163 },
164}
165
166#[unstable(feature = "panic_internals", issue = "none")]
170#[doc(hidden)]
171pub macro const_assert {
172 ($condition: expr, $const_msg:literal, $runtime_msg:literal, $($arg:tt)*) => {{
173 if !($condition) {
174 $crate::panic::const_panic!($const_msg, $runtime_msg, $($arg)*)
175 }
176 }}
177}