Skip to content

Add lint for panic!("{}")#78088

Merged
bors merged 28 commits intorust-lang:masterfrom
fusion-engineering-forks:panic-fmt-lint
Nov 20, 2020
Merged

Add lint for panic!("{}")#78088
bors merged 28 commits intorust-lang:masterfrom
fusion-engineering-forks:panic-fmt-lint

Conversation

@m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Oct 18, 2020

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 for assert!(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.

image

This lint is also a good starting point for adding warnings about panic!(not_a_string) later, once panic_any() becomes a stable alternative.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-diagnostics Area: Messages for errors, warnings, and lints merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.