Skip to content

Lint for let _ = with Drop types? #42366

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

Closed
Ekleog opened this issue Jun 1, 2017 · 2 comments
Closed

Lint for let _ = with Drop types? #42366

Ekleog opened this issue Jun 1, 2017 · 2 comments

Comments

@Ekleog
Copy link

Ekleog commented Jun 1, 2017

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 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?

@F001
Copy link
Contributor

F001 commented Jun 2, 2017

For reference, this issue is in large part a duplication of #40096. And there is an issue in clippy https://github.com/Manishearth/rust-clippy/issues/1574 tracking this.

@nagisa
Copy link
Member

nagisa commented Jun 2, 2017

Closing as a duplicate.

@nagisa nagisa closed this as completed Jun 2, 2017
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

No branches or pull requests

3 participants