Add test for panic!(format!(..)) lint.

This commit is contained in:
Mara Bos 2021-02-14 18:53:10 +01:00
parent a428ab17ab
commit 9f97a0b364
2 changed files with 16 additions and 1 deletions

View file

@ -35,6 +35,8 @@ fn main() {
panic!(a!()); //~ WARN panic message is not a string literal
panic!(format!("{}", 1)); //~ WARN panic message is not a string literal
// Check that the lint only triggers for std::panic and core::panic,
// not any panic macro:
macro_rules! panic {

View file

@ -199,5 +199,18 @@ help: or use std::panic::panic_any instead
LL | std::panic::panic_any(a!());
| ^^^^^^^^^^^^^^^^^^^^^^
warning: 15 warnings emitted
warning: panic message is not a string literal
--> $DIR/non-fmt-panic.rs:38:12
|
LL | panic!(format!("{}", 1));
| ^^^^^^^^^^^^^^^^
|
= 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
|
LL | panic!("{}", 1);
| -- --
warning: 16 warnings emitted