Skip to content

needless_range_loop doesn't recognize anonymous arrays #15309

@abgros

Description

@abgros

These two for loops are equivalent yet needless_range_loop triggers for the second. I would expect it to trigger for none of them, since in both cases the loop variable is being used to index two arrays in parallel.

fn needless_loop() {
	let x = [0; 64];

	// ok
	for i in 0..64 {
		let y = [0; 64];

		black_box(x[i]);
		black_box(y[i]);
	}

	// consider using an iterator and enumerate(): `(i, <item>)`, `x.iter().enumerate()`
	for i in 0..64 {
		black_box(x[i]);
		black_box([0; 64][i]);
	}
}
> cargo clippy --version
clippy 0.1.90 (e466296627 2025-07-17)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions