]> git.lizzy.rs Git - rust.git/blob - src/docs/inefficient_to_string.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / inefficient_to_string.txt
1 ### What it does
2 Checks for usage of `.to_string()` on an `&&T` where
3 `T` implements `ToString` directly (like `&&str` or `&&String`).
4
5 ### Why is this bad?
6 This bypasses the specialized implementation of
7 `ToString` and instead goes through the more expensive string formatting
8 facilities.
9
10 ### Example
11 ```
12 // Generic implementation for `T: Display` is used (slow)
13 ["foo", "bar"].iter().map(|s| s.to_string());
14
15 // OK, the specialized impl is used
16 ["foo", "bar"].iter().map(|&s| s.to_string());
17 ```