Skip to content

Commit 4d39ddd

Browse files
authored
Rollup merge of rust-lang#82113 - m-ou-se:panic-format-lint, r=estebank
Improve non_fmt_panic lint. This change: - fixes the span used by this lint in the case the panic argument is a single macro expansion (e.g. `panic!(a!())`); - adds a suggestion for `panic!(format!(..))` to remove `format!()` instead of adding `"{}", ` or using `panic_any` like it does now; and - fixes the incorrect suggestion to replace `panic![123]` by `panic_any(123]`. Fixes rust-lang#82109. Fixes rust-lang#82110. Fixes rust-lang#82111. Example output: ``` warning: panic message is not a string literal --> src/main.rs:8:12 | 8 | panic!(format!("error: {}", "oh no")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(non_fmt_panic)]` on by default = note: this is no longer accepted in Rust 2021 = note: the panic!() macro supports formatting, so there's no need for the format!() macro here help: remove the `format!(..)` macro call | 8 | panic!("error: {}", "oh no"); | -- -- ``` r? `@estebank`
2 parents 5e98ad3 + 687d200 commit 4d39ddd

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

alloc/src/macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ macro_rules! vec {
107107
/// ```
108108
#[macro_export]
109109
#[stable(feature = "rust1", since = "1.0.0")]
110+
#[cfg_attr(not(test), rustc_diagnostic_item = "format_macro")]
110111
macro_rules! format {
111112
($($arg:tt)*) => {{
112113
let res = $crate::fmt::format($crate::__export::format_args!($($arg)*));

0 commit comments

Comments
 (0)