rust-clippy
rust-clippy copied to clipboard
string_add is overly sensitive when a String is constructed purely to be passed as an argument
Summary
The string_add lint triggers in situations where it makes no sense to put a push_str on a separate line because the String's only purpose is to be fed as an argument.
At the very least, I think this deserves to be acknowledged in the docs.
Lint Name
string_add
Reproducer
I tried this code:
return Url::parse(&("https://".to_owned() + word)).ok();
(it's part of an HTML form spam pre-filter that normalizes loose domain names into Url objects with the help of the Public Suffix List so they get properly evaluated when applying spam rules.)
I saw this happen:
warning: you added something to a string. Consider using `String::push_str()` instead
--> src/lib.rs:210:36
|
210 | return Url::parse(&("https://".to_owned() + word)).ok();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#string_add
I expected to see this happen:
Nothing.
In the code the reproducer is from, word is an immutable slice of a larger string, so String::insert_str isn't an option either.
Version
rustc 1.62.1 (e092d0b6b 2022-07-16)
binary: rustc
commit-hash: e092d0b6b43f2de967af0887873151bb1c0b18d3
commit-date: 2022-07-16
host: x86_64-unknown-linux-gnu
release: 1.62.1
LLVM version: 14.0.5
Additional Labels
No response