Skip to content

.map(|x| x.into()).map(Into::into) #10440

Closed
@fenollp

Description

@fenollp

What it does

This lint replaces the introduction of a simple closure with the named function that is being used in said closure.

Lint Name

replace_mapped_closure_with_into

Category

complexity

Advantage

  • Reduces complexity of the map by introducing a common function name instead of a closure + identifier

Drawbacks

  • May be less readable for newcomers.
  • No performance drawback.

Example

impl IpResource {
    pub fn mac_address(&self) -> Option<MacAddr6> {
        self.mac_address.map(|x| x.into())
    }
}

Could be written as:

impl IpResource {
    pub fn mac_address(&self) -> Option<MacAddr6> {
        self.mac_address.map(Into::into)
    }
}

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