-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Uplift clippy::let_underscore_lock
to rustc
#97241
Comments
@rustbot claim Hi! I'm the person that Cassie from twitter was talking about. I'd like to help work on this issue if possible. There's some additional discussion about the |
So, I was thinking about the use cases for this and was wondering if this is necessarily the right approach to take. In general, locks should contain the values that need mutual exclusion, so that the scope of the lock can be determined simply by how long the values inside are needed. That way, you can simply annotate locking methods with However, there are definitely a fair number of cases where significant drops are useful, described in this section of the nomicon. One thing to consider here is that Rust 1.0 only had lexical drops, meaning that values were always kept until the end of the scope, but nowadays, that can't be guaranteed. Because we don't enforce lexical drops any more, there could be genuine value to some kind of dedicated syntax for these; I'm thinking something along the lines of Python's with mutex.lock() {
// guarded code
} We could then have some sort of attribute like Alternatively, if we don't want to completely enclose the code, we could use something like golang's However, if we don't think that this line of reasoning is justifiable, I think that maybe simply adding this method would do: impl<T> MutexGuard<'_, T> {
pub fn guard<U, F: FnOnce() -> U>(self, f: F) -> U {
let val = f();
drop(self);
val
}
} And, if someone wants to use a lock purely for its effects, they can just call |
Even if we provide a |
What would be wrong with |
The problem is that The best way to handle this is probably something like |
Oh, I see now what the issue is. Yeah… that makes a lot more sense. I seem to have gotten hyperfocused on one aspect of my argument that that part, which is the main part, flew over my head. |
The lint
clippy::let_underscore_lock
should be uplifted into rustc from clippy, as this is such a big potential issue that it shouldn't require people to opt-into clippy to be detected.The text was updated successfully, but these errors were encountered: