Skip to content

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

Closed
@RalfJung

Description

@RalfJung

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions