Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Arnavion opened this issue Feb 18, 2023 · 1 comment · Fixed by #11845
Closed

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

Arnavion opened this issue Feb 18, 2023 · 1 comment · Fixed by #11845
Assignees
Labels
A-lint Area: New lints

Comments

@Arnavion
Copy link
Contributor

Arnavion commented Feb 18, 2023

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());
@Arnavion Arnavion added the A-lint Area: New lints label Feb 18, 2023
@KisaragiEffective
Copy link
Contributor

@rustbot claim

bors added a commit that referenced this issue Nov 23, 2023
…sion, r=flip1995

Extend `result_map_or_into_option` lint to handle `Result::map_or_else(|_| None, Some)`

Fixes #10365.

As indicated in the title, it extends the `result_map_or_into_option` lint to handle `Result::map_or_else(|_| None, Some)`.

changelog: extension of the `result_map_or_into_option` lint to handle `Result::map_or_else(|_| None, Some)`

r? `@blyxyas`
@bors bors closed this as completed in 840e227 Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
2 participants