-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Consider removing mutex_atomic
#4295
Comments
I feel like this lint is correct most of the time; and clippy lints are supposed to be used with a liberal sprinkling of |
My main point is the potential harm of taking action based on a false positive is high compared to other provided lints. |
(I can't comment on the rate of false positive besides saying I have only experienced a 100% false positive rate 😄 ). |
I disagree, lints aren't as strong signals as compiler warnings, and Clippy's warnings are meant to be taken with a grain of salt. Here the signal is "there might be an issue", if you determine it isn't an issue, If you really think there's a problem here a stronger case needs to be made, with lots of examples. |
Like I said, clippy is supposed to be used with a liberal sprinkling of |
Ok, feel free to close if you disagree. |
(leaving open since other maintainers, and other people, may have different opinions) |
The lint mentions in its
I'm with @Manishearth here. I think in the general case this lint is correct and Removing this lint would require to show (with examples), that you need a Mutex in the general case. |
I want to add a +1 since I ran into this reviewing a PR the other day where the submitter defaulted to using I'm quite happy to use the allow feature as noted above but I feel like the lint is a footgun to begin with. Those who know how to use atomics correctly will notice this potential performance issue the moment they see it. |
Filed #8260 to downgrade this lint to Seems that Carl originally proposed to remove this lint completely, but the maintainers rejected it, so I believe downgrading is a reasonable compromise for now. |
Downgrade mutex_atomic to nursery See #1516 and #4295. There are suggestions about removing this lint from the default warned lints in both issues. Also, [`mutex_integer`](https://rust-lang.github.io/rust-clippy/master/index.html#mutex_integer) lint that has the same problems as this lint is in `nursery` group. changelog: Moved [`mutex_atomic`] to `nursery`
* Update 3rd party license file * Allow mutex_atomic clippy lint motivations: rust-lang/rust-clippy#4295
* Update 3rd party license file * Allow mutex_atomic clippy lint rust-lang/rust-clippy#4295 * add more lints to correspond with existing build system * Remove empty trailing lines * Fix cargo home directory in LICENSE-3rdparty file * Export new license file on check fail Co-authored-by: paullegranddc <[email protected]> Co-authored-by: paullegranddc <[email protected]>
* Update 3rd party license file * Allow mutex_atomic clippy lint motivations: rust-lang/rust-clippy#4295
* Update 3rd party license file * Allow mutex_atomic clippy lint rust-lang/rust-clippy#4295 * add more lints to correspond with existing build system * Remove empty trailing lines * Fix cargo home directory in LICENSE-3rdparty file * Export new license file on check fail Co-authored-by: paullegranddc <[email protected]> Co-authored-by: paullegranddc <[email protected]>
I agree that this lint is bad and should be removed. Atomics are very complicated and very easy to get wrong. Mutexes on the other hand are simple and a lot harder to get wrong. People who don't think of using an atomic in the first place shouldn't be directed to using an atomic instead, the mutex will be fine. This like feels a little like if clippy suggested replacing safe but a little more expensive type casts with transmute. Yes, it's faster and often works just as well, but it has a higher maintenance burden and more risk of getting it wrong. We want people to write correct code, not the fastest code imaginable. And if someone knows atomics well enough to use them, they will probably not need this lint in the first place. |
I highly recommending removing this lint. Under complicated code, a person not knowing better would be directed to (incorrectly) use an atomic rather than a mutex, and bugs caused by this may be subtle and occur rarely in practice and may go undiscovered for some time, particularily if the code is rarely or never tested off of x86.
The problem is that people who would recognize when they do and do not need a mutex would also be able to recognize when they should use an atomic vs. when they should use a mutex. The lint will hit two groups of people:
|
It seems this is universally agreed upon that this lint is bad. Should someone make a PR to move this to |
I'm actually not sure if |
Well, this lint is already in nursery since #8260. |
The reason I feel |
Move `mutex_atomic` to `restriction` By #4295, the general consensus seems to be that `mutex_atomic` is not a useful lint in most cases. If anything, it could be useful as a restriction on code that for whatever reason can't use atomics. Keeping it in `clippy::nursery` is harmful to people attempting to use clippy for soundness. --- changelog: Moved [`mutex_atomic`] to `restriction` [#10115](#10115) <!-- chnagelog_checked -->
This lint is also counter-productive advice when the |
Clippy's advice is incorrect here, we need a Mutex for the Condvar to be able to use Condvar::wait. See also: * rust-lang/rust-clippy#1516 * rust-lang/rust-clippy#4295 (comment)
There are many reasons to use mutexes over atomics. Clippy is unable to correctly determine if an atomic is sufficient to replace the mutex use. Attempting to lint over could lead to pushing users to introduce bugs in their code.
I recommend removing this lint.
The text was updated successfully, but these errors were encountered: