-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add lint for panic!("{}") #78088
Add lint for panic!("{}") #78088
Conversation
It now only reacts to expansion of those macros, and suggests inserting `"{}", ` in the right place.
The panic message might contain braces which should never be interpreted as format placeholders, which panic!() will do in a future edition.
r? @estebank (rust_highfive has picked a reviewer for you, use r? to override) |
The beta compiler doesn't accept rustc_diagnostic_items on macros yet.
Clippy already has a lint for |
d971a8c
to
8c142a1
Compare
Clippy does not warn for This lint should be extended later to also provide advice on |
ef4a0d5
to
83bb49f
Compare
f6ef176
to
aaea4fa
Compare
This comment has been minimized.
This comment has been minimized.
aaea4fa
to
6cc8d5e
Compare
This comment has been minimized.
This comment has been minimized.
Rustc itself now warns for all cases that triggered this lint.
6cc8d5e
to
454eaec
Compare
All the clippy issues should be fixed now. Ready for review again. :) |
@bors r+ |
📌 Commit a125ef2 has been approved by |
☀️ Test successful - checks-actions |
Please ping the Clippy team for major changes to Clippy in the Rust repository! We have a lengthy process (by design) in place for deprecating lints. |
@flip1995 apologies, didn't realize that the changes to clippy were being introduced in this PR and not going through clippy's process. I'll keep it in mind for future situations. |
Does this need |
@petrochenkov Good to know, thanks. Now that |
This adds a lint that warns about
panic!("{}")
.panic!(msg)
invocations with a single argument use their argument as panic payload literally, without using it as a format string. The same holds forassert!(expr, msg)
.This lints checks if
msg
is a string literal (after expansion), and warns in case it contained braces. It suggests to insert"{}",
to use the message literally, or to add arguments to use it as a format string.This lint is also a good starting point for adding warnings about
panic!(not_a_string)
later, oncepanic_any()
becomes a stable alternative.