rust-lang / rust-lang/rust-clippy
FP: `clippy::significant_drop_tightening` shows incorrect drop point with `RwLockWriteGuard::downgrade`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
When consuming the RwLockWriteGuard via downgrade, the lint still suggests consuming the lock earlier, and then points at the end of the scope as the drop point and emits a broken suggestion.
Lint Name
significant_drop_tightening
Reproducer
I tried this code:
use std::sync::{RwLock, RwLockWriteGuard};
fn main() {
let lock = RwLock::new(42);
let guard = lock.write().unwrap();
let guard = RwLockWriteGuard::downgrade(guard);
drop(guard);
}
I saw this happen:
warning: temporary with significant `Drop` can be early dropped
--> src/main.rs:5:9
|
3 | fn main() {
| ___________-
4 | | let lock = RwLock::new(42);
5 | | let guard = lock.write().unwrap();
| | ^^^^^
6 | | let guard = RwLockWriteGuard::downgrade(guard);
7 | | drop(guard);
8 | | }
| |_- temporary `guard` is currently being dropped at the end of its contained scope
|
= note: this might lead to unnecessary resource contention
= help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#significant_drop_tightening
= note: `-W clippy::significant-drop-tightening` implied by `-W clippy::nursery`
= help: to override `-W clippy::nursery` add `#[allow(clippy::significant_drop_tightening)]`
help: merge the temporary construction with its single usage
|
5 ~
6 + let guard = lock.write().unwrap().;
7 ~
|
I expected to see this happen:
No lint suggesting to drop the write guard earlier.
No broken suggestion.
Version
rustc 1.92.0 (ded5c06cf 2025-12-08)
binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.92.0
LLVM version: 21.1.3
Additional Labels
@rustbot label +I-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
Start with the significant_drop_tightening lint and reproduce the behavior using the Rust example in the issue. Confirm that RwLockWriteGuard::downgrade does not trigger an early-drop lint or broken suggestion; done means the reproducer emits neither problem.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100