Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Changes from all commits
462ee9c
a466790
5b3b80a
da66a50
f228efc
3beb2e9
451c986
ded269f
b8a8b68
14dcf0a
dd262e3
9615d27
9a840a3
0a9330c
d3b4149
f1fcc4d
dd81c91
9e3b949
ff8df0b
0f193d1
6b44662
190c3ad
1993f1e
5cefc3c
9743f67
a922c6b
454eaec
a125ef2
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A common approach I take to avoid deeply nested
fn
s is to use early returns likeNot necessary to do that now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
let_chains
feature would be nice. But looks like that one still needs more work before it's usable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would happen if a crate I depend on has a
fancy_panic!()
macro that callspanic!()
itself? Would that cause problematic output?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That shows the warning, but not any suggestions (because it doesn't know if extra arguments can be added to
fancy_panic!(..)
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use
", _".repeat(n_arguments),
(or some other placeholder other than_
) here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's tricky to get right. For example:
"{0} {0}"
would only need one argument. This gets even trickier with implicit arguments:"{} {x}"
would work with either one or two additional arguments (e.g.arg0
orarg0, x = arg1
) ifx
is in scope and implements Display.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this is relevant when the panic is being called inside of a separate macro. Could we maybe account for the cases of that being in a local macro to suggest modifying the original macro in this way and if it is from an external macro to ask the crate writer to do so (or maybe just to mention that a newer version of the crate might have solved it)? For that later case we might just want not to emit this lint at all (at least at first).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, that might just not be worth the effort. Let's see how much breaks with the
deny(panic_fmt)
crater run, and how much happens through macros.