Skip to content

Lint against calling to_string() on &&str, &&String, etc. #4586

Closed
@sinkuu

Description

@sinkuu

ToString is specialized for string types to avoid using expensive formatting facility. This specialization can be missed by calling to_string on redundantly-referenced strings like &&str or &&String which may easily occur when working with iterators, for example:

// Generic implementation for `T: Display` is used (slow)
["foo", "bar"].iter().map(|s| s.to_string());

// OK, the specialized impl is used
["foo", "bar"].iter().map(|&s| s.to_string());

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-perfLint: Belongs in the perf lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions