@@ -14,6 +14,7 @@ However, it has [some subtle surprises](https://github.com/rust-lang/rfcs/blob/m
14
14
that we can't just change due to backwards compatibility.
15
15
16
16
``` rust,ignore
17
+ // Rust 2018
17
18
panic!("{}", 1); // Ok, panics with the message "1"
18
19
panic!("{}"); // Ok, panics with the message "{}"
19
20
```
@@ -22,6 +23,7 @@ The `panic!()` macro only uses string formatting when it's invoked with more tha
22
23
When invoked with a single argument, it doesn't even look at that argument.
23
24
24
25
``` rust,ignore
26
+ // Rust 2018
25
27
let a = "{";
26
28
println!(a); // Error: First argument must be a format string literal
27
29
panic!(a); // Ok: The panic macro doesn't care
@@ -43,6 +45,13 @@ Since `panic!()` will no longer accept arbitrary payloads,
43
45
[ ` panic_any() ` ] ( https://doc.rust-lang.org/stable/std/panic/fn.panic_any.html )
44
46
will be the only way to panic with something other than a formatted string.
45
47
48
+ ``` rust,ignore
49
+ // Rust 2021
50
+ panic!("{}", 1); // Ok, panics with the message "1"
51
+ panic!("{}"); // Error, missing argument
52
+ panic!(a); // Error, must be a string literal
53
+ ```
54
+
46
55
In addition, ` core::panic!() ` and ` std::panic!() ` will be identical in Rust 2021.
47
56
Currently, there are some historical differences between those two,
48
57
which can be noticable when switching ` #![no_std] ` on or off.
0 commit comments