rust-lang / rust-lang/rust-clippy

significant_drop_tightening suggests a change that makes no sense

Open
#17,264 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug D-confusing I-false-positive L-nursery
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

The nursery significant_drop_tightening lint can end up suggesting placing a drop in a location that doesn't make sense.

Reproducer

Code:

use std::sync::Arc;

use parking_lot::{Condvar, Mutex};

struct Inner {
  error: Option<String>,
  eof: bool
}

struct Shared {
  inner: Mutex<Inner>,
  signal: Condvar
}

pub enum Outcome {
  HaveData(u64),
  Interrupted,
  Eof
}

pub fn foo(sh: &Arc<Shared>) -> Outcome {
  let mut rw = sh.inner.lock();
  loop {
    if rw.error.is_some() {
      break Outcome::Interrupted;
    } else if rw.eof {
      break Outcome::Eof;
    }
    sh.signal.wait(&mut rw);
  }
}

Cargo.toml contains:

[lints.clippy]
all = { level = "warn", priority = -1 }
cargo = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }

cargo_common_metadata = "allow"

Current output:

Running cargo +beta clippy, includes:

 2  warning: temporary with significant `Drop` can be early dropped
   --> src/main.rs:22:11
    |
 21 |   pub fn foo(sh: &Arc<Shared>) -> Outcome {
    |  _________________________________________-
 22 | |   let mut rw = sh.inner.lock();
    | |           ^^
 23 | |   loop {
 24 | |     if rw.error.is_some() {
 ...  |
 31 | | }
    | |_- temporary `rw` 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/beta/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: drop the temporary after the end of its last usage
    |
 25 ~       break Outcome::Interrupted;
 26 +       drop(rw);

Desired output:
Probably a good idea to suggest placing the drop above the break?

Version
rustc 1.97.0-beta.4 (36645eb0d 2026-06-12)
binary: rustc
commit-hash: 36645eb0d0f62571c8ecc7d1c7446c5da758972f
commit-date: 2026-06-12
host: x86_64-apple-darwin
release: 1.97.0-beta.4
LLVM version: 22.1.6
Additional Labels

No response

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

Start with the significant_drop_tightening lint entry point and reproduce the warning using the Rust code and Cargo lints shown in the issue. Inspect how the suggested drop location is selected around the break expression. Done means the diagnostic no longer suggests an invalid location and instead points to a sensible placement, with the reproducer covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.