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

Different behavior of the let_underscore_lock lint in rustc compared to clippy #102771

Closed
kamulos opened this issue Oct 7, 2022 · 2 comments
Closed
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kamulos
Copy link

kamulos commented Oct 7, 2022

I tried this code with the new rustc lint:

fn main() {
    let _ = std::sync::Mutex::new(()).lock();
}

Clippy warns here, but rustc doesn't. This might be intentional, but I think this could be a source of mistakes...

The rustc lint is triggered, as soon as I use .lock().unwrap()

Meta

rustc --version --verbose:

rustc 1.66.0-nightly (0ca356586 2022-10-06)
binary: rustc
commit-hash: 0ca356586fed56002b10920fd21ddf6fb12de797
commit-date: 2022-10-06
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2
@kamulos kamulos added the C-bug Category: This is a bug. label Oct 7, 2022
@kadiwa4
Copy link
Contributor

kadiwa4 commented Mar 1, 2024

Fixed by #119710:

fn main() {
    let _ = parking_lot::Mutex::new(()).lock();
    let _ = std::sync::Mutex::new(()).lock();
}

results in

result
error: non-binding `let` on a synchronization lock
 --> src/main.rs:2:5
  |
2 |     let _ = parking_lot::Mutex::new(()).lock();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = 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
  = note: `#[deny(clippy::let_underscore_lock)]` on by default

error: non-binding let on a synchronization lock
 --> src/main.rs:3:9
  |
3 |     let _ = std::sync::Mutex::new(()).lock();
  |         ^ this lock is not assigned to a binding and is immediately dropped
  |
  = note: `#[deny(let_underscore_lock)]` on by default
help: consider binding to an unused variable to avoid immediately dropping the value
  |
3 |     let _unused = std::sync::Mutex::new(()).lock();
  |         ~~~~~~~
help: consider immediately dropping the value
  |
3 |     drop(std::sync::Mutex::new(()).lock());
  |     ~~~~~                                +

error: could not compile `playground` (bin "playground") due to 2 previous errors

Tested in tests/ui/lint/let_underscore/let_underscore_lock.rs

@fmease fmease added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage-legacy labels Apr 17, 2024
@fmease
Copy link
Member

fmease commented Apr 17, 2024

Closing as fixed.

@fmease fmease closed this as completed Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants