-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
If I write some code like:
fn stringify(s: &&str) -> String {
s
}
then rustc
will say something like:
1 | fn stringify(s: &&str) -> String {
| ------ expected `String` because of return type
2 | s
| ^- help: try using a conversion method: `.to_string()`
| |
| expected `String`, found `&&str`
But ToString::to_string()
for &&str
uses the default implementation which goes via fmt
.
Even with optimization this is far less efficient than dereferencing the value first (eg: https://godbolt.org/z/rEoo1qv6x)
Ideally we'd have some better combination of an efficient to_string()
override and better advice in error messages.
Metadata
Metadata
Assignees
Labels
C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.