]> git.lizzy.rs Git - rust.git/blob - src/docs/string_to_string.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / string_to_string.txt
1 ### What it does
2 This lint checks for `.to_string()` method calls on values of type `String`.
3
4 ### Why is this bad?
5 The `to_string` method is also used on other types to convert them to a string.
6 When called on a `String` it only clones the `String`, which can be better expressed with `.clone()`.
7
8 ### Example
9 ```
10 // example code where clippy issues a warning
11 let msg = String::from("Hello World");
12 let _ = msg.to_string();
13 ```
14 Use instead:
15 ```
16 // example code which does not raise clippy warning
17 let msg = String::from("Hello World");
18 let _ = msg.clone();
19 ```