Skip to content

Wrong suggestion on while_let_on_iterator #1033

@llogiq

Description

@llogiq

Clippy will suggest to iterate over the supplied value without regards to borrowing. For example,

while let Some(foo) = self.iter.next() { .. }

will lead clippy to produce the following suggestion:

for foo in self.iter { .. }

wich would move iter out of self, which is clearly not what we want. The correct suggestion would be:

for foo in &self.iter { .. }

But only if &self.iter : Iterator<_>. Otherwise the whole lint is wrong, and the while let loop should be left alone.

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.I-false-positiveIssue: The lint was triggered on code it shouldn't haveT-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