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

Clippy doesn't catch Result<T,E>.map_or(None, Some(T)) #5414

Closed
nickrtorres opened this issue Apr 4, 2020 · 0 comments · Fixed by #5415
Closed

Clippy doesn't catch Result<T,E>.map_or(None, Some(T)) #5414

nickrtorres opened this issue Apr 4, 2020 · 0 comments · Fixed by #5415

Comments

@nickrtorres
Copy link
Contributor

Result<T,E> has a method to adapt into an Option<T>, Clippy doesn't catch attempts to rewrite this method as Result<T,E>.map_or(None, Some(T))

flip1995 added a commit to flip1995/rust-clippy that referenced this issue Apr 7, 2020
Add new lint for `Result<T, E>.map_or(None, Some(T))`

Fixes rust-lang#5414

PR Checklist
---
- [x] Followed lint naming conventions (the name is a bit awkward, but it seems to conform)
- [x] Added passing UI tests (including committed .stderr file)
- [x] cargo test passes locally
- [x] Executed cargo dev update_lints
- [x] Added lint documentation
- [x] Run cargo dev fmt

`Result<T, E>` has an [`ok()`](https://doc.rust-lang.org/std/result/enum.Result.html#method.ok) method that adapts a `Result<T,E>` into an `Option<T>`.
It's possible to get around this adapter by writing `Result<T,E>.map_or(None, Some)`.

This lint is implemented as a new variant of the existing [`option_map_none` lint](rust-lang#2128)
@bors bors closed this as completed in a1e49f9 Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant