Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve non_fmt_panic lint. #82113

Merged
merged 9 commits into from
Feb 23, 2021
6 changes: 6 additions & 0 deletions src/test/ui/non-fmt-panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ fn main() {
fancy_panic::fancy_panic!(S);
//~^ WARN panic message is not a string literal

macro_rules! a {
() => { 123 };
}

panic!(a!()); //~ WARN panic message is not a string literal
jyn514 marked this conversation as resolved.
Show resolved Hide resolved

// Check that the lint only triggers for std::panic and core::panic,
// not any panic macro:
macro_rules! panic {
Expand Down
18 changes: 17 additions & 1 deletion src/test/ui/non-fmt-panic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,21 @@ LL | fancy_panic::fancy_panic!(S);
|
= note: this is no longer accepted in Rust 2021

warning: 14 warnings emitted
warning: panic message is not a string literal
--> $DIR/non-fmt-panic.rs:36:12
|
LL | panic!(a!());
| ^^^^
|
= note: this is no longer accepted in Rust 2021
help: add a "{}" format string to Display the message
|
LL | panic!("{}", a!());
| ^^^^^
help: or use std::panic::panic_any instead
|
LL | std::panic::panic_any(a!());
| ^^^^^^^^^^^^^^^^^^^^^^

warning: 15 warnings emitted