rust-clippy
rust-clippy copied to clipboard
FP: `clippy::significant_drop_tightening` shows incorrect drop point with `RwLockWriteGuard::downgrade`
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