Skip to content

map_err mapping to same error type #12110

Open
@cemoktra

Description

@cemoktra

What it does

Detect when map_err maps from error type E to error type E. In those situations the mapping is redundant

Advantage

  • this is like a redundant operation
  • mapping the error one from enum variant to another is likely not what people intend in most cases

Drawbacks

No response

Example

enum Error {
  A,
  B
}

fn source() -> Result<(), Error> { Err(Error::A) }

fn main() -> Result<(), Error> {
  source().map_err(|_| Error::A)
}

Could be written as:

fn main() -> Result<(), Error> {
  source()
}

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