Add test for panic_fmt lint with external panic!()-calling macro.

This commit is contained in:
Mara Bos 2020-10-29 22:21:40 +01:00
parent 9743f67684
commit a922c6b410
3 changed files with 28 additions and 8 deletions

View file

@ -0,0 +1,6 @@
#[macro_export]
macro_rules! fancy_panic {
($msg:expr) => {
panic!($msg)
};
}

View file

@ -1,4 +1,7 @@
// build-pass (FIXME(62277): should be check-pass)
// aux-build:fancy-panic.rs
extern crate fancy_panic;
const C: &str = "abc {}";
static S: &str = "{bla}";
@ -16,6 +19,9 @@ fn main() {
panic!(concat!("{", "}")); //~ WARN panic message contains an unused formatting placeholder
panic!(concat!("{", "{")); //~ WARN panic message contains braces
fancy_panic::fancy_panic!("test {} 123");
//~^ WARN panic message contains an unused formatting placeholder
// Check that the lint only triggers for std::panic and core::panic,
// not any panic macro:
macro_rules! panic {

View file

@ -1,5 +1,5 @@
warning: panic message contains a brace
--> $DIR/panic-brace.rs:8:29
--> $DIR/panic-brace.rs:11:29
|
LL | panic!("here's a brace: {");
| ^
@ -12,7 +12,7 @@ LL | panic!("{}", "here's a brace: {");
| ^^^^^
warning: panic message contains a brace
--> $DIR/panic-brace.rs:9:31
--> $DIR/panic-brace.rs:12:31
|
LL | std::panic!("another one: }");
| ^
@ -24,7 +24,7 @@ LL | std::panic!("{}", "another one: }");
| ^^^^^
warning: panic message contains an unused formatting placeholder
--> $DIR/panic-brace.rs:10:25
--> $DIR/panic-brace.rs:13:25
|
LL | core::panic!("Hello {}");
| ^^
@ -40,7 +40,7 @@ LL | core::panic!("{}", "Hello {}");
| ^^^^^
warning: panic message contains unused formatting placeholders
--> $DIR/panic-brace.rs:11:21
--> $DIR/panic-brace.rs:14:21
|
LL | assert!(false, "{:03x} {test} bla");
| ^^^^^^ ^^^^^^
@ -56,7 +56,7 @@ LL | assert!(false, "{}", "{:03x} {test} bla");
| ^^^^^
warning: panic message contains braces
--> $DIR/panic-brace.rs:13:27
--> $DIR/panic-brace.rs:16:27
|
LL | debug_assert!(false, "{{}} bla");
| ^^^^
@ -68,7 +68,7 @@ LL | debug_assert!(false, "{}", "{{}} bla");
| ^^^^^
warning: panic message contains an unused formatting placeholder
--> $DIR/panic-brace.rs:16:12
--> $DIR/panic-brace.rs:19:12
|
LL | panic!(concat!("{", "}"));
| ^^^^^^^^^^^^^^^^^
@ -84,7 +84,7 @@ LL | panic!("{}", concat!("{", "}"));
| ^^^^^
warning: panic message contains braces
--> $DIR/panic-brace.rs:17:5
--> $DIR/panic-brace.rs:20:5
|
LL | panic!(concat!("{", "{"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -95,5 +95,13 @@ help: add a "{}" format string to use the message literally
LL | panic!("{}", concat!("{", "{"));
| ^^^^^
warning: 7 warnings emitted
warning: panic message contains an unused formatting placeholder
--> $DIR/panic-brace.rs:22:37
|
LL | fancy_panic::fancy_panic!("test {} 123");
| ^^
|
= note: this message is not used as a format string when given without arguments, but will be in a future Rust edition
warning: 8 warnings emitted