rust-lang / rust-lang/rust-clippy

`unwrap_used` lint should check `Option::is_some`

Open
#13,450 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.