Skip to content

New lint: to_string() on a temporary Cow<'_, str> #5987

Closed
@Veetaha

Description

@Veetaha

What it does

The lint is meant to detect calling .to_string() on a temporary Cow<'_, str>.
This is not a rare case when a beginner makes such a mistake.

Categories (optional)

  • Kind: clippy::perf

What is the advantage of the recommended code over the original code:

  • Avoid wasting a potentially owned string inside of the temporary Cow<'_, str>.

Drawbacks

None.

Example

let path_str: String = path.to_string_lossy().to_string();

Could be written as:

let path_str: String = path.to_string_lossy().into_owned();

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions