rust-lang / rust-lang/rust-clippy

new lint: catch creation of Strings from literals where literal/str would do

Open
#5,699 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Let's say we have a function/struct with an argument/field like this:

fn print<T: AsRef<str> + std::fmt::Display>(string: T) {
...
}

When passing literals into it, one could do something like
print(String::from("hello world")); or
print(&String::from("hello world")); or
print(&"hello world");
or even print(&format!("hello world")) // will trigger useless_format but these conversions seem unnecessary because a cheap simple print("hello world"); will do.

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 by reviewing Clippy's existing useless_format lint and the examples in the issue. Determine which literal-to-String constructions should be diagnosed when a literal can be passed directly, then verify the lint covers the listed String::from, borrowed String, and borrowed literal cases without overlapping the existing lint.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.