Skip to content

Warn if user calls .to_string() multiple times on variable. #12152

Open
@Tanguille

Description

@Tanguille

What it does

Warn that .to_string() is only required once. Even with pedantic clippy this doesn't give any warning.

Advantage

It can happen to anyone if you process a lot of code that you accidently call .to_string() more then once on a variable. It takes up useless characters in your file and looks sloppy. This looks like something clippy could fix automatically with the --fix argument.

Drawbacks

I can't think of any since I don't know any situation where it would make sense to call .to_string() twice in a variable.

Example

 let uri = req.uri().path().to_string().to_string();

Could be written as:

 let uri = req.uri().path().to_string();

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