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

Lint against panic!(format!(...)) and assert!(..., format!(...)) #6259

Closed
RalfJung opened this issue Oct 28, 2020 · 4 comments
Closed

Lint against panic!(format!(...)) and assert!(..., format!(...)) #6259

RalfJung opened this issue Oct 28, 2020 · 4 comments
Labels
A-lint Area: New lints

Comments

@RalfJung
Copy link
Member

RalfJung commented Oct 28, 2020

What it does

assert! and panic! have built-in support for formatting, but they also accept arguments of type String, so one could use format! instead.

Using format! here is entirely unnecessary, and yet happens in the wild, so this seems like a useful target for a Clippy lint. Also the long-term plan is to not support String arguments any more, so such code might not work in future editions.

Cc @m-ou-se

Example

panic!(format!("hello {}", var))
assert!(x, format!("hello {}", var))

Could be written as:

panic!("hello {}", var)
assert!(x, "hello {}", var)
@RalfJung RalfJung added the A-lint Area: New lints label Oct 28, 2020
@m-ou-se
Copy link
Member

m-ou-se commented Oct 28, 2020

It will probably be very soon that rustc itself has a lint for panic!(not-a-string-literal) and assert!(expr, not-a-string-literal) (to warn about the potential upcoming edition change), so it might not be worth it to add this to Clippy now.

@giraffate
Copy link
Contributor

related issue: #5013

@giraffate
Copy link
Contributor

#3155 is also a related issue.

@camsteffen
Copy link
Contributor

Added in #7743

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

4 participants