RS.CLIPPY.STRING_ADD
Using `x + ..` where x is a `String` instead of `push_str()`
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: string_add. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for all instances of x + _ where x is of type
String, but only if string_add_assign does not
match.
Why restrict this?
This particular
Add implementation is asymmetric (the other operand need not be String,
but x does), while addition as mathematically defined is symmetric, and
the String::push_str(_) function is a perfectly good replacement.
Therefore, some dislike it and wish not to have it in their code.
That said, other people think that string addition, having a long tradition
in other languages is actually fine, which is why we decided to make this
particular lint allow by default.
Example
let x = "Hello".to_owned();
x + ", World";
Use instead:
let mut x = "Hello".to_owned();
x.push_str(", World");