Skip to content

New lint: if let Some iter element #6564

Closed
@camsteffen

Description

@camsteffen

What it does

Checks for iteration of Options with if let Some inside. Can use flatten() instead. The lint should also work in iter.for_each().

Categories (optional)

  • Kind: complexity

What is the advantage of the recommended code over the original code

It is simpler.

Drawbacks

None.

Example

for x in y {
    if let Some(z) = x {
        println!("{}", z);
    }
}

Could be written as:

for z in y.flatten() {
    println!("{}", z);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-complexityLint: Belongs in the complexity lint groupgood 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