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

Suggest get_mut() instead of lock() method on Mutex #1765

Closed
kryptan opened this issue May 15, 2017 · 1 comment · Fixed by #6103
Closed

Suggest get_mut() instead of lock() method on Mutex #1765

kryptan opened this issue May 15, 2017 · 1 comment · Fixed by #6103
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types

Comments

@kryptan
Copy link

kryptan commented May 15, 2017

If you have mut reference to a Mutex then get_mut method is more efficient than lock since it doesn't require locking. If clippy detects such situation it could suggest to use get_mut instead of lock.

@oli-obk oli-obk added good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints T-middle Type: Probably requires verifiying types labels May 16, 2017
@oli-obk
Copy link
Contributor

oli-obk commented May 16, 2017

You need to use expr_ty instead of expr_ty_adjusted on the self argument of the lock call and check whether it's a mutable reference or a name of something that's mutable.

We can't detect whether we have immutable ownership to the value. so let foo = Mutex::new(...); foo.lock().... won't trigger :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants