@@ -29,7 +29,8 @@ println!(a); // Error: First argument must be a format string literal
29
29
panic!(a); // Ok: The panic macro doesn't care
30
30
```
31
31
32
- (It even accepts non-strings such as ` panic!(123) ` , which is uncommon and rarely useful.)
32
+ It even accepts non-strings such as ` panic!(123) ` , which is uncommon and rarely useful since it
33
+ produces a surprisingly unhelpful message: ` panicked at 'Box<Any>' ` .
33
34
34
35
This will especially be a problem once
35
36
[ implicit format arguments] ( https://rust-lang.github.io/rfcs/2795-format-args-implicit-identifiers.html )
@@ -54,4 +55,28 @@ panic!(a); // Error, must be a string literal
54
55
55
56
In addition, ` core::panic!() ` and ` std::panic!() ` will be identical in Rust 2021.
56
57
Currently, there are some historical differences between those two,
57
- which can be noticable when switching ` #![no_std] ` on or off.
58
+ which can be noticeable when switching ` #![no_std] ` on or off.
59
+
60
+ ## Migration
61
+
62
+ A lint, ` non_fmt_panics ` , gets triggered whenever there is some call to ` panic ` that uses some
63
+ deprecated behavior that will error in Rust 2021. The ` non_fmt_panics ` lint has already been a warning
64
+ by default on all editions since the 1.50 release (with several enhancements made in later releases).
65
+ If your code is already warning free, then it should already be ready to go for Rust 2021!
66
+
67
+ You can automatically migrate your code to be Rust 2021 Edition compatible or ensure it is already compatible by
68
+ running:
69
+
70
+ ``` sh
71
+ cargo fix --edition
72
+ ```
73
+
74
+ Should you choose to or need to manually migrate, you'll need to update all panic invocations to either use the same
75
+ formatting as ` println ` currently does or use
76
+
77
+ For example, in the case of ` panic!(MyStruct) ` , you'll need to either convert to using ` std::panic::panic_any ` (note
78
+ that this is a function not a macro).
79
+
80
+ In the case of panic messages that include curly braces but no arguments (e.g., `panic!("Some curlies: {}")), you'll
81
+ need to print the literal string by either using the same syntax as ` println! ` (i.e., ` panic!("{}", Some curlies: {}") ` )
82
+ or by escaping them (i.e., ` panic!("Some curlies: {{}}") ` ).
0 commit comments