Skip to content

Commit

Permalink
Add test for panic_fmt lint with external panic!()-calling macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Oct 29, 2020
1 parent 9743f67 commit a922c6b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/test/ui/auxiliary/fancy-panic.rs
@@ -0,0 +1,6 @@
#[macro_export]
macro_rules! fancy_panic {
($msg:expr) => {
panic!($msg)
};
}
6 changes: 6 additions & 0 deletions src/test/ui/panic-brace.rs
@@ -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}";
Expand All @@ -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 {
Expand Down
24 changes: 16 additions & 8 deletions src/test/ui/panic-brace.stderr
@@ -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: {");
| ^
Expand All @@ -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: }");
| ^
Expand All @@ -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 {}");
| ^^
Expand All @@ -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");
| ^^^^^^ ^^^^^^
Expand All @@ -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");
| ^^^^
Expand All @@ -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!("{", "}"));
| ^^^^^^^^^^^^^^^^^
Expand All @@ -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!("{", "{"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -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

0 comments on commit a922c6b

Please sign in to comment.