Open
Description
Summary
Since Rust 1.82.0 users can replace std::iter::repeat(x).take(m).collect::<String>()
by the (almost equivalent) std::iter::repeat_n(x,m).collect::<String>()
. Both are manual versions of string repeat, but only the former emits a warning.
I would be happy to try to contribute a PR for this if the maintainers agree that this is a false negative.
Thanks for clippy, it's the best!
Lint Name
manual_str_repeat
Reproducer
I tried this code:
fn main() {
let text: String = std::iter::repeat_n('a',5).collect();
println!("{text}");
}
I expected to see this happen:
Checking playground v0.0.1 (/playground)
warning: manual implementation of `str::repeat` using iterators
--> src/main.rs:2:24
|
2 | let text: String = std::iter::repeat_n('a',5).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"a".repeat(5)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat
= note: `#[warn(clippy::manual_str_repeat)]` on by default
Instead, this happened:
(no warning emitted)
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity