rust-lang / rust-lang/rust-clippy
new lint: catch creation of Strings from literals where literal/str would do
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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