rust-lang / rust-lang/rust-clippy
New lint: map then unwrap
Open
@king-11 is already working on this.
Since Nov 21, 2021.
A-lint
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Detects usage of map(..).unwrap()
Categories (optional)
Kind: pedantic
What is the advantage of the recommended code over the original code
The unwrap effectively only applies to the value before .map(..), so putting it after .map(..) needlessly complicates the semantics of the code.
Drawbacks
None.
Example
opt.map(|n| n * 2).unwrap()
Could be written as:
opt.unwrap() * 2
This should also work with expect as well as maybe other Option and Result transformers like filter.
I think the name map_unwrap is good, even though other method combinations are applicable.
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.
Assessment
This issue has not been assessed yet.