rustc suggests calling to_string() on &&str
but this generates inefficient code.
#128690
Labels
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
I-heavy
Issue: Problems and improvements with respect to binary size of generated code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
If I write some code like:
then
rustc
will say something like:(see: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c01bf377e97a0b1c90bd374ba90663a6)
But
ToString::to_string()
for&&str
uses the default implementation which goes viafmt
.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.The text was updated successfully, but these errors were encountered: