Skip to content

lint unnecessary .into_iter() #1094

Closed
@zackmdavis

Description

@zackmdavis

for loops implicitly call .into_iter() on that which is being iterated over, but if someone didn't know this, they might have written .into_iter() themselves (this is not merely a hypothetical scenario), which is surely bad style.

Example of code that should get a warning (but does not as of Clippy v. 0.0.79):

fn main() {
    let my_vec = vec![1, 2, 3, 4];
    for i in my_vec.into_iter() {
        println!("{}", i);
    }
}

(could be just for i in my_vec {)

I'm guessing the implementation would probably be pretty similar to that of the existing explicit_iter_loop lint?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesT-middleType: Probably requires verifiying typesgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions