Skip to content

Suggest removing "empty" format! for types that implement fmt::Display #15121

Open
@LynxDev2

Description

@LynxDev2

What it does

When format!("{x}") or format!("{}", x) is used and the type of x implements fmt::Display, clippy should suggest using .to_string() directly

I'm not sure if there's already an issue for this, but I couldn't find one

Advantage

No response

Drawbacks

No response

Example

let addr = SocketAddr::from(([127, 0, 0, 1], 80));
let addr_string = format!("{addr}");

Could be written as:

let addr = SocketAddr::from(([127, 0, 0, 1], 80));
let addr_string = addr.to_string();

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