Parse the format string for the panic_fmt lint for better warnings.

This commit is contained in:
Mara Bos 2020-10-20 22:25:42 +02:00
parent 0f193d1a62
commit 6b44662669
5 changed files with 47 additions and 21 deletions

View file

@ -5,6 +5,6 @@ fn main() {
panic!("here's a brace: {"); //~ WARN panic message contains a brace
std::panic!("another one: }"); //~ WARN panic message contains a brace
core::panic!("Hello {}"); //~ WARN panic message contains an unused formatting placeholder
assert!(false, "{:03x} bla"); //~ WARN panic message contains an unused formatting placeholder
assert!(false, "{:03x} {test} bla"); //~ WARN panic message contains unused formatting placeholders
debug_assert!(false, "{{}} bla"); //~ WARN panic message contains a brace
}

View file

@ -24,35 +24,35 @@ LL | std::panic!("{}", "another one: }");
| ^^^^^
warning: panic message contains an unused formatting placeholder
--> $DIR/panic-brace.rs:7:18
--> $DIR/panic-brace.rs:7:25
|
LL | core::panic!("Hello {}");
| ^^^^^^^^^^
| ^^
|
= note: this message is not used as a format string when given without arguments, but will be in a future Rust version
help: add the missing argument(s)
|
LL | core::panic!("Hello {}", argument);
| ^^^^^^^^^^
LL | core::panic!("Hello {}", ...);
| ^^^^^
help: or add a "{}" format string to use the message literally
|
LL | core::panic!("{}", "Hello {}");
| ^^^^^
warning: panic message contains an unused formatting placeholder
--> $DIR/panic-brace.rs:8:20
warning: panic message contains unused formatting placeholders
--> $DIR/panic-brace.rs:8:21
|
LL | assert!(false, "{:03x} bla");
| ^^^^^^^^^^^^
LL | assert!(false, "{:03x} {test} bla");
| ^^^^^^ ^^^^^^
|
= note: this message is not used as a format string when given without arguments, but will be in a future Rust version
help: add the missing argument(s)
|
LL | assert!(false, "{:03x} bla", argument);
| ^^^^^^^^^^
LL | assert!(false, "{:03x} {test} bla", ...);
| ^^^^^
help: or add a "{}" format string to use the message literally
|
LL | assert!(false, "{}", "{:03x} bla");
LL | assert!(false, "{}", "{:03x} {test} bla");
| ^^^^^
warning: panic message contains a brace