rust-lang / rust-lang/rust-clippy

allow_unwrap_types

Open
#16,535 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

allow_unwrap_types configures unwrap_used to allow any type in a given list of types to be unwrapped.

Advantage

Avoids the need to #[allow] unwrap() various types.

A concrete example is to allow unwrap() of std::sync::LockResult which is produced by locking a Mutex.

Drawbacks

None.

Example
#[allow(clippy::unwrap_used)]
some_mutex
    .lock()
    .unwrap()
    ...;

Could be written as:

some_mutex
    .lock()
    .unwrap()
    ...;

with the following in Cargo.toml:

[lints.clippy]
allow_unwrap_types = [std::sync::LockResult]
Comparison with existing lints

When the unwrap_used lint is applied, the user is forced to pepper their code with #[allow(clippy::unwrap_used)] when, for example, Mutex lock results are unwrapped.

Additional Context

The reasonableness of unwrapping LockResult is discussed here: https://www.reddit.com/r/rust/comments/10f6328/is_this_a_reasonable_way_to_handle_unwrapping/.

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

No files or tests are named. Start with Clippy's existing unwrap_used lint and the configuration shown in the issue, then trace how lint settings and type lists are handled. Done means allow_unwrap_types accepts the listed types and permits matching unwrap() calls without an explicit allow.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.