Skip to content

clippy::clone_on_copy following recommendation on lock guards can lead to dead locks #12957

Description

@juliusl

Summary

Consider a RwLock on a Clone and/or Copy type.

static VAL: std::sync::RwLock<bool> = std::sync::RwLock::new(false);

Typically, when acquiring a read lock the caller should try to drop the read guard as soon as possible. So on types that are cloneable it's straightforward to call .clone().

When fixing a bunch of lint issues and seeing the calling clone_on_copy lint, the easiest fix is to remove .clone(), which will compile. However, this can result in a deadlock since the previous guard will no longer be dropped without an explicit dereference.

Is it possible for the lint to skip types that are Drop + Copy or Drop + Clone?

Reproducer

No response

Version

No response

Additional Labels

@rustbot l-suggestion-causes-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-triageStatus: PR was triaged and is waiting for an action from a maintainer (closing/moving/... the PR)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions