Skip to content

new lint for &str to String conversion #2824

Open
@mockersf

Description

@mockersf

There are a few different ways to convert from a &str to a String:

fn main() {
    let _: String = "hello".to_owned();
    let _: String = "hello".to_string();
    let _: String = "hello".into();
    let _: String = String::from("hello");
    let _: String = format!("hello");
}

Without going into a discussion about which is the best (this lint has been deprecated), I think a lint to ensure the same one is used throughout a crate would be interesting.

This could be done either through configuration, or by keeping stats on which is used and then emit warning for the non majority one.

I can work on it, but wanted to have a general point of view before. What do you think ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-styleLint: Belongs in the style lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions