Skip to content

useless_format: .to_string() suggested where format! could be omitted #3361

Description

@matthiaskrgr

clippy 0.0.212 (5afdf8b 2018-10-14)

in this code

fn main() {
    let _: &str = &format!("hello");
}

clippy suggests

warning: useless use of `format!`
 --> src/main.rs:2:20
  |
2 |     let _: &str = &format!("hello");
  |                    ^^^^^^^^^^^^^^^^ help: consider using .to_string(): `"hello".to_string()`
  |

but I think a better solution would be to simply omit the format!() like
let _: &str = &"hello";
or
let _: &str = "hello";

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    L-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions