-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
Summary
needless_range_loop
does not fire if accessing an array in a loop if the array is held in an object.
Lint Name
needless_range_loop
Reproducer
I tried this code:
struct Data<const N: usize>([u64; N]);
fn example<const N: usize>(data: Data<N>) -> u64 {
let mut sum = 0;
for i in 0..N {
// Does not trigger the lint
sum += data.0[i];
// Uncomment below to trigger lint
// let array = &data.0;
// sum += array[i];
}
sum
}
I expected to see this happen:
needless_range_loop
lint to trigger when accessing data.0[i]
in the loop. It fires when accessing the array directly through a reference (see commented out section).
Instead, this happened:
The lint did not fire
Version
rustc 1.89.0 (29483883e 2025-08-04)
binary: rustc
commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2
commit-date: 2025-08-04
host: x86_64-unknown-linux-gnu
release: 1.89.0
LLVM version: 20.1.7
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't