Skip to content

Use is_some_and when appropriate #9125

Closed
@pcd1193182

Description

@pcd1193182

What it does

The lint would detect cases where the new Option function is_some_and would be appropriate. Examples would be places where map() converts an Option<T> into an Option<bool> and then unwrap_or(false) is used. The library function is still experimental, but once it's stable, this would be a useful modernization suggestion.

Lint Name

option_is_some_with

Category

complexity

Advantage

Reduces function calls (even if they would optimize down), increases clarity.

Drawbacks

Low priority, since the existing approaches are functional, if less idiomatic/aesthetic.

Example

let x: Option<int> = Some(7);
x.map(|val| val > 5).unwrap_or(false)

Could be written as:

let x: Option<int> = Some(7);
x.is_some_and(|val| val > 5)

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