rust-lang / rust-lang/rust-clippy
`clippy::clone_on_copy` following recommendation on lock guards can lead to dead locks
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names the clippy::clone_on_copy lint but provides no source files, tests, or reproducer. Start by locating that lint's implementation and existing tests, then evaluate the lock-guard scenario described in the issue; done means the recommendation no longer permits the reported deadlock risk, with regression coverage for the relevant case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100