Skip to content

Suggest Result::ok() for result.map_or_else(|_| None, Some) #10365

Closed
@Arnavion

Description

@Arnavion

What it does

See title and example.

This lint should only fire if:

  1. the Err closure does nothing else except return None, and...
  2. the Ok parameter is Some

There is already a lint result_map_or_into_option but that only covers r.map_or(None, Some), so this can either be a new lint or result_map_or_into_option can be extended to also check for this.

Lint Name

result_map_or_else_into_option

Category

style

Advantage

The suggested code makes it more obvious what the code is doing.

Drawbacks

None.

Example

assert_eq!(Some(1), r.map_or_else(|_| None, Some));

Could be written as:

assert_eq!(Some(1), r.ok());

Metadata

Metadata

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