Skip to content

needless_range_loop suggests using iter on a value that do not have iter method #1014

Closed
@malbarbo

Description

@malbarbo

In this example:

use std::ops::Index;

struct S(Vec<u32>);

impl Index<usize> for S {
    type Output = u32;

    fn index(&self, index: usize) -> &u32 {
        &self.0[index]
    }
}

fn main() {
    let s = S(vec![1, 2, 3]);

    for i in 0..3 {
        println!("{:?}", s[i]);
    }
}

Clippy says "Consider using for item in s.iter().take(3), but s does not have iter method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.T-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions