rust-lang / rust-lang/rust-clippy

Suggest using Cow on mixture of &'static str + Strings

Open
#320 8 comments 0 reactions 1 assignee View on GitHub

@llogiq is already working on this.

Since Sep 15, 2015.

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

Description

I see a lot of owned strings in many places where a Cow<'static, str> will do. The latter will likely improve performance.

How do we detect this? It's a value of type String which are only initialized with other Strings from elsewhere or &'static str (via .to_owned()/.to_string()). Also we should probably check if the value is part of the public interface (as we did recently with wrong_pub_self_convention).

I think this should be possible with the ExprUseVisitor – so I finally have a reason to check it out. 😄

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.