Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manual_str_repeat should trigger for repeat_n with msrv 1.82 #13784

Open
dylwil3 opened this issue Dec 5, 2024 · 0 comments
Open

manual_str_repeat should trigger for repeat_n with msrv 1.82 #13784

dylwil3 opened this issue Dec 5, 2024 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@dylwil3
Copy link

dylwil3 commented Dec 5, 2024

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)

@dylwil3 dylwil3 added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

1 participant