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

Be explicit about when mutex guard is dropped. #151

Merged
merged 1 commit into from
Dec 6, 2022
Merged

Be explicit about when mutex guard is dropped. #151

merged 1 commit into from
Dec 6, 2022

Conversation

tjni
Copy link
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
Collaborator

Naturally.

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

@tjni
Copy link
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
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