rust-lang / rust-lang/rust-clippy

new lint for &str to String conversion

Open
#2,824 7 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint L-style
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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 ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's four Rust conversion examples and review the deprecated str_to_string lint linked in the description. Resolve whether the lint should use explicit configuration or infer the crate's majority style, then define how non-majority conversions are identified and what behavior marks the work complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.