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

Should pick up panic!(format!( #5013

Closed
heca-project opened this issue Jan 7, 2020 · 4 comments
Closed

Should pick up panic!(format!( #5013

heca-project opened this issue Jan 7, 2020 · 4 comments
Labels
A-lint Area: New lints L-style Lint: Belongs in the style lint group T-macros Type: Issues with macros and macro expansion

Comments

@heca-project
Copy link

clippy should detect unnecessary format! blocks, such as panic!(format!( and others.

@flip1995 flip1995 added L-perf Lint: Belongs in the perf lint group A-lint Area: New lints T-macros Type: Issues with macros and macro expansion L-style Lint: Belongs in the style lint group and removed L-perf Lint: Belongs in the perf lint group labels Jan 7, 2020
@blasrodri
Copy link

clippy should detect unnecessary format! blocks, such as panic!(format!( and others.

Can you be more specific in which cases this should be added? I guess you refer to some sort of short circuiting that makes some expression to remain unevaluated no matter what. Is that correct?

In particular, the case with panic! and format! does not follow those rules. For instance

#[derive(Debug)]
struct Whatever;

fn main() {
  let b = Whatever;
  panic!(format!("^^ {:?} ^^ ", b)) // prints ^^ Whatever ^^
}

@flip1995
Copy link
Member

panic!(format!(..)) is always weird, since panic!() uses the same formatting syntax as fromat! and you could just remove the format! and it'll have the same output.

@flip1995
Copy link
Member

This should also warn on other macros of the panic family unreachable/assert/...

@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 L-style Lint: Belongs in the style lint group T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

No branches or pull requests

4 participants