diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-02-23 16:10:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-23 16:10:21 +0100 |
| commit | 547b3adfe4afb7cfe3d3603e16faa458913ef56f (patch) | |
| tree | 9ab0c55b4ec5df5a65f4d5d182561516993ffc56 /library/alloc/src | |
| parent | 18d12844330df90ac4d309dc545902551634a251 (diff) | |
| parent | ad93f48d770cc8cfe473e809700201c31550bc68 (diff) | |
| download | rust-547b3adfe4afb7cfe3d3603e16faa458913ef56f.tar.gz rust-547b3adfe4afb7cfe3d3603e16faa458913ef56f.zip | |
Rollup merge of #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 #82109.
Fixes #82110.
Fixes #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`
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/macros.rs | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index a64a8b32ad7..6a64587a223 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -107,6 +107,7 @@ macro_rules! vec { /// ``` #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] +#[cfg_attr(not(test), rustc_diagnostic_item = "format_macro")] macro_rules! format { ($($arg:tt)*) => {{ let res = $crate::fmt::format($crate::__export::format_args!($($arg)*)); |
