rust-lang / rust-lang/rust-clippy
New lint: Detect Ok(foo?) patterns and suggest .map_err(From::from) instead.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
When I started writing Rust code I used to do the following pattern to convert Result types. Turns out I am not the only one doing it, and I think it's fairly common. When I learned more about the From and Into traits I noticed .map_err(From::from) could be used instead which seems cleaner.
So instead of writing this:
fn bar() -> Result<File, MyError> {
Ok(File::open("foo.txt")?)
}
It could suggest this:
fn bar() -> Result<File, MyError> {
File::open("foo.txt").map_err(From::from)
}
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
No source file or test entry point is named. Start by reviewing Clippy's existing lint implementations and how Rust handles Result expressions with ?; done means detecting the shown Ok(foo?) pattern and suggesting the equivalent .map_err(From::from) form without changing other cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100