rust-lang / rust-lang/rust-clippy
Disallow `.map_err(...).ok()` pattern
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
I recently observed a code pattern where a Result was converted to an Option with an unnecessary map_err invocation along the way.
Lint Name
map_err_ok
Category
restriction
Advantage
Removes a call to map_err where the error value that is generated is immediately discarded.
Drawbacks
No response
Example
let x = something_that_returns_result()
.map_err(|_e| Error::SomeOtherError)
.ok();
Could be written as:
let x = something_that_returns_result().ok();
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The requested entry point is the map_err_ok restriction lint; start by reviewing comparable restriction lints in rust-clippy and the example pattern in the issue. Add coverage for the shown Result-to-Option case and verify that the lint flags the redundant map_err while preserving the direct .ok() form.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100