Skip to content

Be explicit about when mutex guard is dropped.#151

Merged
nabijaczleweli merged 1 commit intothecoshman:developfrom
tjni:mutex-guard-drop
Dec 6, 2022
Merged

Be explicit about when mutex guard is dropped.#151
nabijaczleweli merged 1 commit intothecoshman:developfrom
tjni:mutex-guard-drop

Conversation

@tjni
Copy link
Copy Markdown
Contributor

@tjni tjni commented Dec 6, 2022

In Rust 1.65, rust-lang/rust#97739 was merged, which adds a new lint against the pattern:

let _ = cond_var.wait(...).unwrap()

leading to:

error: non-binding let on a synchronization lock
   --> src/main.rs:185:9
    |
185 |     let _ = end_handler.wait(mx.lock().unwrap()).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
    |
185 |     let _unused = end_handler.wait(mx.lock().unwrap()).unwrap();
    |         ~~~~~~~
help: consider immediately dropping the value
    |
185 |     drop(end_handler.wait(mx.lock().unwrap()).unwrap());
    |     ~~~~~                                             +

error: could not compile `https` due to previous error

This patch applies the second suggestion to be explicit about dropping the returned MutexGuard, which maintains the current behavior. (If the guard should live until the scope ends, I'll update this to use the first suggestion.)

@tjni tjni mentioned this pull request Dec 6, 2022
13 tasks
@nabijaczleweli nabijaczleweli merged commit 6e4c8e9 into thecoshman:develop Dec 6, 2022
@nabijaczleweli
Copy link
Copy Markdown
Collaborator

Naturally.

Applied, idk when this will land in a release, given pirate's recent proclivities.

@tjni
Copy link
Copy Markdown
Contributor Author

tjni commented Dec 6, 2022

Thank you!

@tjni tjni deleted the mutex-guard-drop branch December 6, 2022 22:49
@nabijaczleweli
Copy link
Copy Markdown
Collaborator

Released in absentia in v1.12.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants