Skip to content

allow_unwrap_types #16535

@glyn

Description

@glyn

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/.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions