Skip to content

New lint: map then unwrap #7763

@camsteffen

Description

@camsteffen

What it does

Detects usage of map(..).unwrap()

Categories (optional)

Kind: pedantic

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

The unwrap effectively only applies to the value before .map(..), so putting it after .map(..) needlessly complicates the semantics of the code.

Drawbacks

None.

Example

opt.map(|n| n * 2).unwrap()

Could be written as:

opt.unwrap() * 2

This should also work with expect as well as maybe other Option and Result transformers like filter.

I think the name map_unwrap is good, even though other method combinations are applicable.

Metadata

Metadata

Assignees

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