Skip to content

map_collect_result_unit does not recognize for loop #7710

@matthiasbeyer

Description

@matthiasbeyer

What it does

This is a suggestion for the map_collect_result_unit lint.
I just refactored this piece of code:

fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { for (uuid, err) in self.0.iter() { writeln!(f, "{}: {}", uuid, err)?; } Ok(()) }

into this:

fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.0.iter().map(|(uuid, err)| writeln!(f, "{}: {}", uuid, err)).collect() }

And then the lint told me that I can do

fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.0.iter().try_for_each(|(uuid, err)| writeln!(f, "{}: {}", uuid, err)) }

But maybe it is possible that the lint also tells me that my first version can be written better?

I don't know whether this is possible, but it would be nice to catch the for-loop-version as well here.

Categories (optional)

  • Kind: clippy::style

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions