rust-lang / rust-lang/rust-clippy
Suggest using `String::extend` where appropriate
@saberoueslati is already working on this.
Since Sep 17, 2026.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
The String type has some Extend implementations, and the lint suggests using those instead of pushing in a loop.
Advantage
- More concise
- I suspect it optimizes better
Drawbacks
No response
Example
for c in s.chars() {
out_string.push(c);
}
Could be written as:
out_string.extend(s.chars());
And similar for e.g. String::push_str in a loop
Comparison with existing lints
The closest related lint I can find is string_extend_chars, which would replace the output for the example I provided with out_string.push_str(s);. For other Iterator<char>s (e.g. core::char::ToLowercase was the iterator I was using when inspired to make this issue ticket), the String::extend call would most likely be the last suggestion we can make.
Additional Context
It might be reasonable to extend to other data structures beyond just Strings.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.