You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had an uncomfortable moment today, noticing my let _ = mutex.lock() didn't actually keep a lock on the mutex for the scope (it's just a Mutex<()>, given it's for some unsafe mmapped shared resource, design choice may be criticized but I think irrelevant to the issue). Changing it to let _a = mutex.lock() fixed it.
I raised this up on #rust-unternals, and @nox and Mutabah helped me understand (I think) why this was a sensible design choice (that is, _ not moving the value but leaving it where it was, in this case the temporary).
Now, I think this is treacherous, and could lead to security issues when used unknowingly from unsafe code (or deadlocks or other things from normal code), as I did before knowing (thankfully discovered thanks to unit tests).
So I think maybe a warning lint could be added when assigning a Drop type to _, as this 1/ would maybe not be often legitimately done (I think?), and 2/ may have unexpected consequences on the drop order.
What do you think about this?
The text was updated successfully, but these errors were encountered:
Hello,
I had an uncomfortable moment today, noticing my
let _ = mutex.lock()
didn't actually keep a lock on the mutex for the scope (it's just aMutex<()>
, given it's for some unsafe mmapped shared resource, design choice may be criticized but I think irrelevant to the issue). Changing it tolet _a = mutex.lock()
fixed it.I raised this up on #rust-unternals, and @nox and Mutabah helped me understand (I think) why this was a sensible design choice (that is,
_
not moving the value but leaving it where it was, in this case the temporary).Now, I think this is treacherous, and could lead to security issues when used unknowingly from
unsafe
code (or deadlocks or other things from normal code), as I did before knowing (thankfully discovered thanks to unit tests).So I think maybe a warning lint could be added when assigning a
Drop
type to_
, as this 1/ would maybe not be often legitimately done (I think?), and 2/ may have unexpected consequences on the drop order.What do you think about this?
The text was updated successfully, but these errors were encountered: