]> git.lizzy.rs Git - rust.git/blob - library/core/src/panic.rs
Fix two false positive lints
[rust.git] / library / core / src / panic.rs
1 //! Panic support in the standard library.
2
3 #![stable(feature = "core_panic_info", since = "1.41.0")]
4
5 mod location;
6 mod panic_info;
7 mod unwind_safe;
8
9 use crate::any::Any;
10
11 #[stable(feature = "panic_hooks", since = "1.10.0")]
12 pub use self::location::Location;
13 #[stable(feature = "panic_hooks", since = "1.10.0")]
14 pub use self::panic_info::PanicInfo;
15 #[stable(feature = "catch_unwind", since = "1.9.0")]
16 pub 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(core_panic, const_format_args)]
21 #[rustc_diagnostic_item = "core_panic_2015_macro"]
22 #[rustc_macro_transparency = "semitransparent"]
23 pub macro panic_2015 {
24     () => (
25         $crate::panicking::panic("explicit panic")
26     ),
27     ($msg:literal $(,)?) => (
28         $crate::panicking::panic($msg)
29     ),
30     // Use `panic_str` instead of `panic_display::<&str>` for non_fmt_panic lint.
31     ($msg:expr $(,)?) => (
32         $crate::panicking::panic_str($msg)
33     ),
34     // Special-case the single-argument case for const_panic.
35     ("{}", $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)+))
40     ),
41 }
42
43 #[doc(hidden)]
44 #[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
45 #[allow_internal_unstable(core_panic, const_format_args)]
46 #[rustc_diagnostic_item = "core_panic_2021_macro"]
47 #[rustc_macro_transparency = "semitransparent"]
48 pub macro panic_2021 {
49     () => (
50         $crate::panicking::panic("explicit panic")
51     ),
52     // Special-case the single-argument case for const_panic.
53     ("{}", $arg:expr $(,)?) => (
54         $crate::panicking::panic_display(&$arg)
55     ),
56     ($($t:tt)+) => (
57         $crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
58     ),
59 }
60
61 /// An internal trait used by libstd to pass data from libstd to `panic_unwind`
62 /// and other panic runtimes. Not intended to be stabilized any time soon, do
63 /// not use.
64 #[unstable(feature = "std_internals", issue = "none")]
65 #[doc(hidden)]
66 pub unsafe trait BoxMeUp {
67     /// Take full ownership of the contents.
68     /// The return type is actually `Box<dyn Any + Send>`, but we cannot use `Box` in libcore.
69     ///
70     /// After this method got called, only some dummy default value is left in `self`.
71     /// Calling this method twice, or calling `get` after calling this method, is an error.
72     ///
73     /// The argument is borrowed because the panic runtime (`__rust_start_panic`) only
74     /// gets a borrowed `dyn BoxMeUp`.
75     fn take_box(&mut self) -> *mut (dyn Any + Send);
76
77     /// Just borrow the contents.
78     fn get(&mut self) -> &(dyn Any + Send);
79 }