Using `let_underscore_lock` with my own types?

I love the new let_underscore_lock lint that gives errors like

error: non-binding let on a synchronization lock
   --> tests/common.rs:426:13
    |
426 |         let _ = lock.lock().unwrap();
    |             ^   ^^^^^^^^^^^^^^^^^^^^ this binding will immediately drop the value assigned to it
    |             |
    |             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
    |
426 |         let _unused = lock.lock().unwrap();
    |             ~~~~~~~
help: consider immediately dropping the value
    |
426 |         drop(lock.lock().unwrap());
    |         ~~~~~                    +

and am wondering if there is any way to get this kind of error for my own guard types?

3 Likes

As an open source project you could make an attempt at implementing it. There's already an open issue with some details.

That ticket is for clippy, but the lint I'm talking about is in rustc. I was hoping that when the lint was implemented in rustc something more general was used (like in that issue). Or that perhaps there was a workaround I could use.

Ugh. Sorry about that.

No problem, it's the same thing that's had me running in circles for a while now.

Skimming the linked issues, it's actually less general now (still a specific list; no parking lot).

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.