Skip to content

useless_format does not play well with format arg capture #8290

Closed
@matthiaskrgr

Description

@matthiaskrgr

Summary

Clippy does not yet understand fully understand format!("{x}"); yet.
This probably needs to be a msrvlint.

Reproducer

I tried this code:

fn main() {
    let x = "hello";
    let _string = format!("{x}");
}

I expected to see this happen:
Clippy should suggest something like x.to_string() but instead suggests {x}.to_string()

Instead, this happened:

warning: useless use of `format!`
 --> src/main.rs:3:19
  |
3 |     let _string = format!("{x}");
  |                   ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `{x}.to_string()`
  |
  = note: `#[warn(clippy::useless_format)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format

Version

`clippy 0.1.60 (38c22af 2022-01-15)`

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedP-highPriority: High

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions