rust-lang / rust-lang/rust-clippy

Warn about `Mutex<()>`

Open
#4,471 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint L-correctness
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

I can't think of a use case where this actually gives you any guarantees. You can still use it to protect another Sync data structure, but you can just as well forget to do so. One should always put the components that are protected into the Mutex even if not strictly necessary due to the componentes being thread safe themselves.

An example of such a situation would be

struct Foo {
    lock: Mutex<()>,
    a: AtomicUsize,
    b: AtomicUsize,
}

where one should not modify the two values one by one, but always together in a single critical section.

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

Use the issue body and its Mutex<()> example as the starting specification. First determine the intended warning scope and how it should handle protected Sync data structures and paired AtomicUsize values; done means the warning behavior and its false-positive boundaries are defined and verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.