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

if let Some with locked mutex #11773

Open
road2react opened this issue Nov 8, 2023 · 0 comments
Open

if let Some with locked mutex #11773

road2react opened this issue Nov 8, 2023 · 0 comments
Labels
A-lint Area: New lints

Comments

@road2react
Copy link

What it does

This can cause deadlocks. Similar to #5219 but with locks inside the if clause outside of the else clause.

Advantage

No response

Drawbacks

No response

Example

if let Some(value) = mutex.lock().unwrap().do_something() {
  *mutex.lock().unwrap() = new_value();
}

Could be written as:

let value = mutex.lock().unwrap().do_something();
if let Some(value) = value {
  *mutex.lock().unwrap() = new_value();
}

or

let guard = mutex.lock().unwrap();
if let Some(value) = guard.do_something() {
  *guard = new_value();
}
@road2react road2react added the A-lint Area: New lints label Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

1 participant