]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/string_add.txt
Auto merge of #104673 - matthiaskrgr:rollup-85f65ov, r=matthiaskrgr
[rust.git] / src / tools / clippy / src / docs / string_add.txt
1 ### What it does
2 Checks for all instances of `x + _` where `x` is of type
3 `String`, but only if [`string_add_assign`](#string_add_assign) does *not*
4 match.
5
6 ### Why is this bad?
7 It's not bad in and of itself. However, this particular
8 `Add` implementation is asymmetric (the other operand need not be `String`,
9 but `x` does), while addition as mathematically defined is symmetric, also
10 the `String::push_str(_)` function is a perfectly good replacement.
11 Therefore, some dislike it and wish not to have it in their code.
12
13 That said, other people think that string addition, having a long tradition
14 in other languages is actually fine, which is why we decided to make this
15 particular lint `allow` by default.
16
17 ### Example
18 ```
19 let x = "Hello".to_owned();
20 x + ", World";
21 ```
22
23 Use instead:
24 ```
25 let mut x = "Hello".to_owned();
26 x.push_str(", World");
27 ```