Skip to content

FP: clippy::significant_drop_tightening shows incorrect drop point with RwLockWriteGuard::downgrade #16216

@edwloef

Description

@edwloef

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions