Skip to content

Commit a922c6b

Browse files
committed
Add test for panic_fmt lint with external panic!()-calling macro.
1 parent 9743f67 commit a922c6b

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/test/ui/auxiliary/fancy-panic.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_export]
2+
macro_rules! fancy_panic {
3+
($msg:expr) => {
4+
panic!($msg)
5+
};
6+
}

src/test/ui/panic-brace.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// build-pass (FIXME(62277): should be check-pass)
2+
// aux-build:fancy-panic.rs
3+
4+
extern crate fancy_panic;
25

36
const C: &str = "abc {}";
47
static S: &str = "{bla}";
@@ -16,6 +19,9 @@ fn main() {
1619
panic!(concat!("{", "}")); //~ WARN panic message contains an unused formatting placeholder
1720
panic!(concat!("{", "{")); //~ WARN panic message contains braces
1821

22+
fancy_panic::fancy_panic!("test {} 123");
23+
//~^ WARN panic message contains an unused formatting placeholder
24+
1925
// Check that the lint only triggers for std::panic and core::panic,
2026
// not any panic macro:
2127
macro_rules! panic {

src/test/ui/panic-brace.stderr

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: panic message contains a brace
2-
--> $DIR/panic-brace.rs:8:29
2+
--> $DIR/panic-brace.rs:11:29
33
|
44
LL | panic!("here's a brace: {");
55
| ^
@@ -12,7 +12,7 @@ LL | panic!("{}", "here's a brace: {");
1212
| ^^^^^
1313

1414
warning: panic message contains a brace
15-
--> $DIR/panic-brace.rs:9:31
15+
--> $DIR/panic-brace.rs:12:31
1616
|
1717
LL | std::panic!("another one: }");
1818
| ^
@@ -24,7 +24,7 @@ LL | std::panic!("{}", "another one: }");
2424
| ^^^^^
2525

2626
warning: panic message contains an unused formatting placeholder
27-
--> $DIR/panic-brace.rs:10:25
27+
--> $DIR/panic-brace.rs:13:25
2828
|
2929
LL | core::panic!("Hello {}");
3030
| ^^
@@ -40,7 +40,7 @@ LL | core::panic!("{}", "Hello {}");
4040
| ^^^^^
4141

4242
warning: panic message contains unused formatting placeholders
43-
--> $DIR/panic-brace.rs:11:21
43+
--> $DIR/panic-brace.rs:14:21
4444
|
4545
LL | assert!(false, "{:03x} {test} bla");
4646
| ^^^^^^ ^^^^^^
@@ -56,7 +56,7 @@ LL | assert!(false, "{}", "{:03x} {test} bla");
5656
| ^^^^^
5757

5858
warning: panic message contains braces
59-
--> $DIR/panic-brace.rs:13:27
59+
--> $DIR/panic-brace.rs:16:27
6060
|
6161
LL | debug_assert!(false, "{{}} bla");
6262
| ^^^^
@@ -68,7 +68,7 @@ LL | debug_assert!(false, "{}", "{{}} bla");
6868
| ^^^^^
6969

7070
warning: panic message contains an unused formatting placeholder
71-
--> $DIR/panic-brace.rs:16:12
71+
--> $DIR/panic-brace.rs:19:12
7272
|
7373
LL | panic!(concat!("{", "}"));
7474
| ^^^^^^^^^^^^^^^^^
@@ -84,7 +84,7 @@ LL | panic!("{}", concat!("{", "}"));
8484
| ^^^^^
8585

8686
warning: panic message contains braces
87-
--> $DIR/panic-brace.rs:17:5
87+
--> $DIR/panic-brace.rs:20:5
8888
|
8989
LL | panic!(concat!("{", "{"));
9090
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -95,5 +95,13 @@ help: add a "{}" format string to use the message literally
9595
LL | panic!("{}", concat!("{", "{"));
9696
| ^^^^^
9797

98-
warning: 7 warnings emitted
98+
warning: panic message contains an unused formatting placeholder
99+
--> $DIR/panic-brace.rs:22:37
100+
|
101+
LL | fancy_panic::fancy_panic!("test {} 123");
102+
| ^^
103+
|
104+
= note: this message is not used as a format string when given without arguments, but will be in a future Rust edition
105+
106+
warning: 8 warnings emitted
99107

0 commit comments

Comments
 (0)