Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy::let_underscore_lock false-positive when binding mutex without locking #8486

Closed
daprilik opened this issue Mar 1, 2022 · 1 comment · Fixed by #8990
Closed

clippy::let_underscore_lock false-positive when binding mutex without locking #8486

daprilik opened this issue Mar 1, 2022 · 1 comment · Fixed by #8990
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@daprilik
Copy link

daprilik commented Mar 1, 2022

Summary

let_underscore_lock should only fire if the .lock() method is being invoked (and/or the type being bound is a lock guard)

Lint Name

let_underscore_lock

Reproducer

I tried this code:

pub fn main() {
    let x = parking_lot::Mutex::new(0);
    let _ = x;
}

I saw this happen:

    Checking playground v0.0.1 (/playground)
error: non-binding let on a synchronization lock
 --> src/main.rs:3:5
  |
3 |     let _ = x;
  |     ^^^^^^^^^^
  |
  = note: `#[deny(clippy::let_underscore_lock)]` on by default
  = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_lock

I expected to see this happen:

Nothing

Version

rustc 1.59.0 (9d1b2106e 2022-02-23)
binary: rustc
commit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a
commit-date: 2022-02-23
host: x86_64-pc-windows-msvc
release: 1.59.0
LLVM version: 13.0.0

Additional Labels

No response

@daprilik daprilik added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 1, 2022
@daprilik
Copy link
Author

daprilik commented Mar 1, 2022

Scanning through the code, the issue seems to be caused by these lines:

&paths::PARKING_LOT_RAWMUTEX,
&paths::PARKING_LOT_RAWRWLOCK,

These are paths should be pointing at the lock guards, rather than the locks themselves.

bors added a commit that referenced this issue Jun 25, 2022
Fix `let_undescore_lock` false-positive when binding without locking

Fixes #8486.

changelog: Fix `let_undescore_lock` false-positive when binding without locking.
@bors bors closed this as completed in 889b361 Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant