Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sinkuu opened this issue Sep 27, 2019 · 4 comments · Fixed by #4683
Closed

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

sinkuu opened this issue Sep 27, 2019 · 4 comments · Fixed by #4683
Labels
A-lint Area: New lints L-perf Lint: Belongs in the perf lint group

Comments

@sinkuu
Copy link
Contributor

sinkuu commented Sep 27, 2019

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());
@JohnTitor JohnTitor added the A-lint Area: New lints label Sep 27, 2019
@HMPerson1
Copy link
Contributor

I can work on this

@mati865

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Oct 4, 2019

Error: This repository is not enabled to use triagebot.
Add a triagebot.toml in the root of the master branch to enable it.

Please let @rust-lang/release know if you're having trouble with this bot.

@mati865
Copy link
Member

mati865 commented Oct 4, 2019

Oh #4595 wasn't merged.

@flip1995 flip1995 added the L-perf Lint: Belongs in the perf lint group label Oct 5, 2019
@bors bors closed this as completed in 14a0f36 Oct 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints L-perf Lint: Belongs in the perf lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants