]> git.lizzy.rs Git - rust.git/blob - src/docs/useless_format.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / useless_format.txt
1 ### What it does
2 Checks for the use of `format!("string literal with no
3 argument")` and `format!("{}", foo)` where `foo` is a string.
4
5 ### Why is this bad?
6 There is no point of doing that. `format!("foo")` can
7 be replaced by `"foo".to_owned()` if you really need a `String`. The even
8 worse `&format!("foo")` is often encountered in the wild. `format!("{}",
9 foo)` can be replaced by `foo.clone()` if `foo: String` or `foo.to_owned()`
10 if `foo: &str`.
11
12 ### Examples
13 ```
14 let foo = "foo";
15 format!("{}", foo);
16 ```
17
18 Use instead:
19 ```
20 let foo = "foo";
21 foo.to_owned();
22 ```