@@ -8,8 +8,8 @@ tests. `panic!` is closely tied with the `unwrap` method of both
88[ ` Option ` ] [ ounwrap ] and [ ` Result ` ] [ runwrap ] enums. Both implementations call
99` panic! ` when they are set to [ ` None ` ] or [ ` Err ` ] variants.
1010
11- When using ` panic!() ` you can specify a string payload, that is built using
12- the [ ` format! ` ] syntax. That payload is used when injecting the panic into
11+ When using ` panic!() ` you can specify a string payload that is built using
12+ [ formatting syntax] . That payload is used when injecting the panic into
1313the calling Rust thread, causing the thread to panic entirely.
1414
1515The behavior of the default ` std ` hook, i.e. the code that runs directly
@@ -18,6 +18,7 @@ after the panic is invoked, is to print the message payload to
1818call. You can override the panic hook using [ ` std::panic::set_hook() ` ] .
1919Inside the hook a panic can be accessed as a ` &dyn Any + Send ` ,
2020which contains either a ` &str ` or ` String ` for regular ` panic!() ` invocations.
21+ (Whether a particular invocation contains the payload at type ` &str ` or ` String ` is unspecified and can change.)
2122To panic with a value of another other type, [ ` panic_any ` ] can be used.
2223
2324See also the macro [ ` compile_error! ` ] , for raising errors during compilation.
@@ -55,7 +56,7 @@ For more detailed information about error handling check out the [book] or the
5556[ `panic_any` ] : ../std/panic/fn.panic_any.html
5657[ `Box` ] : ../std/boxed/struct.Box.html
5758[ `Any` ] : crate::any::Any
58- [ `format!` ] : ../std/macro.format .html
59+ [ `format!` syntax ] : ../std/fmt/index .html
5960[ book ] : ../book/ch09-00-error-handling.html
6061[ `std::result` ] : ../std/result/index.html
6162
@@ -64,6 +65,29 @@ For more detailed information about error handling check out the [book] or the
6465If the main thread panics it will terminate all your threads and end your
6566program with code ` 101 ` .
6667
68+ # Editions
69+
70+ Behavior of the panic macros changed over editions.
71+
72+ ## 2021 and later
73+
74+ In Rust 2021 and later, ` panic! ` always requires a format string and
75+ the applicable format arguments, and is the same in ` core ` and ` std ` .
76+ Use [ ` std::panic::panic_any(x) ` ] ( ../std/panic/fn.panic_any.html ) to
77+ panic with an arbitrary payload.
78+
79+ ## 2018 and 2015
80+
81+ In Rust Editions prior to 2021, ` std::panic!(x) ` with a single
82+ argument directly uses that argument as a payload.
83+ This is true even if the argument is a string literal.
84+ For example, ` panic!("problem: {reason}") ` panics with a
85+ payload of literally ` "problem: {reason}" ` (a ` &'static str ` ).
86+
87+ ` core::panic!(x) ` with a single argument requires that ` x ` be ` &str ` ,
88+ but otherwise behaves like ` std::panic! ` . In particular, the string
89+ need not be a literal, and is not interpreted as a format string.
90+
6791# Examples
6892
6993``` should_panic
0 commit comments