2018-01-23 09:31:53 -06:00
|
|
|
//! Panic support in the standard library.
|
|
|
|
|
2019-11-26 03:47:08 -06:00
|
|
|
#![stable(feature = "core_panic_info", since = "1.41.0")]
|
2018-01-23 09:31:53 -06:00
|
|
|
|
2021-04-28 10:31:33 -05:00
|
|
|
mod location;
|
|
|
|
mod panic_info;
|
2021-04-28 10:39:23 -05:00
|
|
|
mod unwind_safe;
|
2021-04-28 10:31:33 -05:00
|
|
|
|
2019-04-14 21:23:21 -05:00
|
|
|
use crate::any::Any;
|
2021-04-28 10:31:33 -05:00
|
|
|
|
|
|
|
#[stable(feature = "panic_hooks", since = "1.10.0")]
|
|
|
|
pub use self::location::Location;
|
|
|
|
#[stable(feature = "panic_hooks", since = "1.10.0")]
|
|
|
|
pub use self::panic_info::PanicInfo;
|
2021-04-28 10:39:23 -05:00
|
|
|
#[stable(feature = "catch_unwind", since = "1.9.0")]
|
|
|
|
pub use self::unwind_safe::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe};
|
2018-01-23 09:31:53 -06:00
|
|
|
|
2021-01-09 09:52:06 -06:00
|
|
|
#[doc(hidden)]
|
|
|
|
#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
|
2021-07-09 09:45:50 -05:00
|
|
|
#[allow_internal_unstable(core_panic, const_format_args)]
|
2021-01-09 09:52:06 -06:00
|
|
|
#[rustc_diagnostic_item = "core_panic_2015_macro"]
|
|
|
|
#[rustc_macro_transparency = "semitransparent"]
|
|
|
|
pub macro panic_2015 {
|
|
|
|
() => (
|
|
|
|
$crate::panicking::panic("explicit panic")
|
|
|
|
),
|
|
|
|
($msg:literal $(,)?) => (
|
|
|
|
$crate::panicking::panic($msg)
|
|
|
|
),
|
2021-09-14 13:14:37 -05:00
|
|
|
// Use `panic_str` instead of `panic_display::<&str>` for non_fmt_panic lint.
|
2021-01-09 09:52:06 -06:00
|
|
|
($msg:expr $(,)?) => (
|
|
|
|
$crate::panicking::panic_str($msg)
|
|
|
|
),
|
2021-09-14 13:14:37 -05:00
|
|
|
// Special-case the single-argument case for const_panic.
|
|
|
|
("{}", $arg:expr $(,)?) => (
|
|
|
|
$crate::panicking::panic_display(&$arg)
|
|
|
|
),
|
2021-01-09 09:52:06 -06:00
|
|
|
($fmt:expr, $($arg:tt)+) => (
|
2021-07-09 09:45:50 -05:00
|
|
|
$crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+))
|
2021-01-09 09:52:06 -06:00
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
|
2021-07-09 09:45:50 -05:00
|
|
|
#[allow_internal_unstable(core_panic, const_format_args)]
|
2021-01-09 09:52:06 -06:00
|
|
|
#[rustc_diagnostic_item = "core_panic_2021_macro"]
|
|
|
|
#[rustc_macro_transparency = "semitransparent"]
|
|
|
|
pub macro panic_2021 {
|
|
|
|
() => (
|
|
|
|
$crate::panicking::panic("explicit panic")
|
|
|
|
),
|
2021-09-14 13:14:37 -05:00
|
|
|
// Special-case the single-argument case for const_panic.
|
|
|
|
("{}", $arg:expr $(,)?) => (
|
|
|
|
$crate::panicking::panic_display(&$arg)
|
|
|
|
),
|
2021-01-09 09:52:06 -06:00
|
|
|
($($t:tt)+) => (
|
2021-07-09 09:45:50 -05:00
|
|
|
$crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
|
2021-01-09 09:52:06 -06:00
|
|
|
),
|
|
|
|
}
|
|
|
|
|
2022-01-21 16:04:06 -06:00
|
|
|
#[doc(hidden)]
|
|
|
|
#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
|
|
|
|
#[allow_internal_unstable(core_panic)]
|
|
|
|
#[rustc_diagnostic_item = "unreachable_2015_macro"]
|
|
|
|
#[rustc_macro_transparency = "semitransparent"]
|
|
|
|
pub macro unreachable_2015 {
|
|
|
|
() => (
|
|
|
|
$crate::panicking::panic("internal error: entered unreachable code")
|
|
|
|
),
|
|
|
|
// Use of `unreachable_display` for non_fmt_panic lint.
|
2022-03-16 07:12:30 -05:00
|
|
|
// NOTE: the message ("internal error ...") is embedded directly in unreachable_display
|
2022-01-21 16:04:06 -06:00
|
|
|
($msg:expr $(,)?) => (
|
|
|
|
$crate::panicking::unreachable_display(&$msg)
|
|
|
|
),
|
|
|
|
($fmt:expr, $($arg:tt)*) => (
|
|
|
|
$crate::panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
|
|
|
|
#[allow_internal_unstable(core_panic)]
|
|
|
|
#[rustc_diagnostic_item = "unreachable_2021_macro"]
|
|
|
|
#[rustc_macro_transparency = "semitransparent"]
|
|
|
|
pub macro unreachable_2021 {
|
|
|
|
() => (
|
|
|
|
$crate::panicking::panic("internal error: entered unreachable code")
|
|
|
|
),
|
|
|
|
($($t:tt)+) => (
|
|
|
|
$crate::panic!("internal error: entered unreachable code: {}", $crate::format_args!($($t)+))
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
2018-03-29 16:59:13 -05:00
|
|
|
/// An internal trait used by libstd to pass data from libstd to `panic_unwind`
|
|
|
|
/// and other panic runtimes. Not intended to be stabilized any time soon, do
|
|
|
|
/// not use.
|
2019-12-21 05:16:18 -06:00
|
|
|
#[unstable(feature = "std_internals", issue = "none")]
|
2018-03-29 16:59:13 -05:00
|
|
|
#[doc(hidden)]
|
|
|
|
pub unsafe trait BoxMeUp {
|
2019-11-26 02:24:39 -06:00
|
|
|
/// Take full ownership of the contents.
|
2019-11-25 05:16:08 -06:00
|
|
|
/// The return type is actually `Box<dyn Any + Send>`, but we cannot use `Box` in libcore.
|
2019-11-26 02:24:39 -06:00
|
|
|
///
|
2019-11-25 05:16:08 -06:00
|
|
|
/// After this method got called, only some dummy default value is left in `self`.
|
2019-11-26 02:24:39 -06:00
|
|
|
/// Calling this method twice, or calling `get` after calling this method, is an error.
|
|
|
|
///
|
|
|
|
/// The argument is borrowed because the panic runtime (`__rust_start_panic`) only
|
|
|
|
/// gets a borrowed `dyn BoxMeUp`.
|
2019-11-25 05:16:08 -06:00
|
|
|
fn take_box(&mut self) -> *mut (dyn Any + Send);
|
2019-11-26 02:24:39 -06:00
|
|
|
|
|
|
|
/// Just borrow the contents.
|
2018-07-10 13:39:28 -05:00
|
|
|
fn get(&mut self) -> &(dyn Any + Send);
|
2018-03-29 16:59:13 -05:00
|
|
|
}
|