rust-lang / rust-lang/rust-clippy
`unwrap_used` lint should check `Option::is_some`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
I've encountered an issue with the linting for unwrap_used in my codebase. The lint should check Option::is_some, like unnecessary_unwrap
Lint Name
clippy::unwrap-used
Reproducer
I tried this code:
pub fn extract(option: Option<usize>)->usize {
if option.is_some() {
return option.unwrap();
}
0
}
I tried this command:
cargo clippy -- -A clippy::all -W clippy::unwrap_used
I expected to see this happen:
No warning.
Instead, this happened:
option.unwrap() is reported.
Version
rustc 1.81.0-nightly (4bc39f028 2024-06-26)
binary: rustc
commit-hash: 4bc39f028d14c24b04dd17dc425432c6ec354536
commit-date: 2024-06-26
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7
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
Start at the clippy::unwrap_used lint entry point and compare its handling with unnecessary_unwrap, using the reproducer and cargo clippy command in the issue. Done means the shown is_some guard no longer triggers unwrap_used while unguarded unwrap cases remain covered by the lint tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100