Skip to content

Commit 1abc1e2

Browse files
committed
Add test for non_fmt_panic lint for panic!(some_macro!()).
1 parent ef778e7 commit 1abc1e2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/test/ui/non-fmt-panic.rs

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ fn main() {
2929
fancy_panic::fancy_panic!(S);
3030
//~^ WARN panic message is not a string literal
3131

32+
macro_rules! a {
33+
() => { 123 };
34+
}
35+
36+
panic!(a!()); //~ WARN panic message is not a string literal
37+
3238
// Check that the lint only triggers for std::panic and core::panic,
3339
// not any panic macro:
3440
macro_rules! panic {

src/test/ui/non-fmt-panic.stderr

+17-1
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,21 @@ LL | fancy_panic::fancy_panic!(S);
183183
|
184184
= note: this is no longer accepted in Rust 2021
185185

186-
warning: 14 warnings emitted
186+
warning: panic message is not a string literal
187+
--> $DIR/non-fmt-panic.rs:36:12
188+
|
189+
LL | panic!(a!());
190+
| ^^^^
191+
|
192+
= note: this is no longer accepted in Rust 2021
193+
help: add a "{}" format string to Display the message
194+
|
195+
LL | panic!("{}", a!());
196+
| ^^^^^
197+
help: or use std::panic::panic_any instead
198+
|
199+
LL | std::panic::panic_any(a!());
200+
| ^^^^^^^^^^^^^^^^^^^^^^
201+
202+
warning: 15 warnings emitted
187203

0 commit comments

Comments
 (0)