Skip to content

manual_str_repeat should trigger for repeat_n with msrv 1.82 #13784

Open
@dylwil3

Description

@dylwil3

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.

Playground link

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

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions