Skip to content

Add unnecessary_option_map_or_else #14588

Open
@sorairolake

Description

@sorairolake

What it does

Checks for usage of .map_or_else() "map closure" for Option type.

Advantage

This can be written more concisely by using unwrap_or_else().

Drawbacks

No response

Example

let k = 10;
let x: Option<u32> = Some(4);
let y = x.map_or_else(|| 2 * k, |n| n);

Could be written as:

let k = 10;
let x: Option<u32> = Some(4);
let y = x.unwrap_or_else(|| 2 * k);

Summary Notes

Generated by triagebot, see help for how to add more

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsgood 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