Skip to content

Commit 76b8b00

Browse files
authored
Rollup merge of #74622 - fusion-engineering-forks:panic-box, r=KodrAus
Add std::panic::panic_any. The discussion of #67984 lead to the conclusion that there should be a macro or function separate from `std::panic!()` for throwing arbitrary payloads, to make it possible to deprecate or disallow (in edition 2021) `std::panic!(arbitrary_payload)`. Alternative names: - `panic_with!(..)` - ~~`start_unwind(..)`~~ (panicking doesn't always unwind) - `throw!(..)` - `panic_throwing!(..)` - `panic_with_value(..)` - `panic_value(..)` - `panic_with(..)` - `panic_box(..)` - `panic(..)` The equivalent (private, unstable) function in `libstd` is called `std::panicking::begin_panic`. I suggest `panic_any`, because it allows for any (`Any + Send`) type. _Tracking issue: #78500_
2 parents 3478d7c + b48fee0 commit 76b8b00

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

library/std/src/panic.rs

+14
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ pub use crate::panicking::{set_hook, take_hook};
2323
#[stable(feature = "panic_hooks", since = "1.10.0")]
2424
pub use core::panic::{Location, PanicInfo};
2525

26+
/// Panic the current thread with the given message as the panic payload.
27+
///
28+
/// The message can be of any (`Any + Send`) type, not just strings.
29+
///
30+
/// The message is wrapped in a `Box<'static + Any + Send>`, which can be
31+
/// accessed later using [`PanicInfo::payload`].
32+
///
33+
/// See the [`panic!`] macro for more information about panicking.
34+
#[unstable(feature = "panic_any", issue = "78500")]
35+
#[inline]
36+
pub fn panic_any<M: Any + Send>(msg: M) -> ! {
37+
crate::panicking::begin_panic(msg);
38+
}
39+
2640
/// A marker trait which represents "panic safe" types in Rust.
2741
///
2842
/// This trait is implemented by default for many types and behaves similarly in

0 commit comments

Comments
 (0)