Uh oh!
There was an error while loading. Please reload this page.
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.
rust-highfive
commented
Oct 18, 2020
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.
matthiaskrgr
commented
Oct 18, 2020
Clippy already has a lint for |
Uh oh!
There was an error while loading. Please reload this page.
m-ou-se
commented
Oct 18, 2020
m-ou-se
commented
Oct 18, 2020
Clippy does not warn for This lint should be extended later to also provide advice on |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
f6ef176 to
aaea4faCompare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Rustc itself now warns for all cases that triggered this lint.
m-ou-se
commented
Nov 19, 2020
All the clippy issues should be fixed now. Ready for review again. :) |
estebank
commented
Nov 19, 2020
@bors r+ |
bors
commented
Nov 19, 2020
📌 Commit a125ef2 has been approved by |
bors
commented
Nov 20, 2020
bors
commented
Nov 20, 2020
☀️ Test successful - checks-actions |
flip1995
commented
Nov 20, 2020
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. |
estebank
commented
Nov 23, 2020
@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. |
pthariensflame
commented
Jan 1, 2021
Does this need |
petrochenkov
commented
Jan 23, 2021
@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
msgis 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.