Skip to content

Unneded iter for loop #14430

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

Open
Snowiiii opened this issue Mar 18, 2025 · 1 comment · May be fixed by #14443
Open

Unneded iter for loop #14430

Snowiiii opened this issue Mar 18, 2025 · 1 comment · May be fixed by #14443
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy

Comments

@Snowiiii
Copy link

Snowiiii commented Mar 18, 2025

Summary

Hello, While coding on my Rust project i encountered something that would definitely make sense to have as a clippy lint.

Problematic code

let array = [1, 2, 3];
for (i, _) in array.iter().enumerate() {
     // the array data is not used we only need the len 
}

Better alternative

let array = [1, 2, 3];
for i in 0..array.len() {
     // we only use the len
}

This is cleaner and also may faster since we don't have to iterate over the array anymore

Lint Name

uneeded_iter_loop

Reproducer

I tried this code:

let array = [1, 2, 3];
for (i, _) in array.iter().enumerate() {
     // the array data is not used we only need the len 
}

I expected to see this happen:
A clippy warn

Instead, this happened:
No clippy warn

Version

rustc: 1.85-stable
@Snowiiii Snowiiii 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 Mar 18, 2025
@samueltardieu samueltardieu added good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints and removed 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 Mar 18, 2025
@profetia
Copy link
Contributor

@rustbot claim

@profetia profetia linked a pull request Mar 20, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants