Unnecessary call to to_string
when the underlying type implements AsRef<str>
#7933
Labels
A-lint
Area: New lints
What it does
Checks for expressions of the form
&X.to_string()
, used in a position requiring a&str
, whereX
implementsAsRef<str>
.In such a case, the call to
to_string
is unnecessary.Similar to
to_string
/AsRef<str>
, there's alsoto_path_buf
/AsRef<Path>
andto_vec
/AsRef<[T]>
.There are probably others.
I am happy to tackle this if we can agree on the check, and whether it is useful.
Categories (optional)
Drawbacks
Potential "false positives" if
X
'sAsRef<str>
andto_string
implementations produce different strings. But I would expect such cases to be rare.Example
The text was updated successfully, but these errors were encountered: