-
Notifications
You must be signed in to change notification settings - Fork 1.6k
significant_drop_in_scrutinee
: Fix false positives due to false drops of place expressions
#12764
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @blyxyas (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
MutexGuard<_> Has a significant drop (the attribute) (the drop function itself), I'm not sure why do you think that it doesn't have one. Could you elaborate? Maybe I'm not understanding something correctly, as mutexes are quite a deep topic. |
It's For example, I've added a unit test for this: struct Guard<'a, T>(MutexGuard<'a, T>);
impl<'a, T> Guard<'a, T> {
fn guard(&self) -> &MutexGuard<T> {
&self.0
}
} match guard.guard().len() {
0 => println!("empty"),
_ => println!("not empty"),
}
Actually, I think it's rare for this to happen in real-world scenarios (which is why no one has complained about it). However, I do think that the previous logic does not seem correct in this sense. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! ❤️
Sorry for the delay, I'm currently working on a pretty big change that will optimize the linting module in Rust (both Clippy and builtin lints) by about 50%. So I've been focusing on that optimization. (I also wanted to make sure that everything's right)
@bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Thanks for the explanation. That's pretty cool 👍, and I completely understand that you're busy, so the review may be delayed (though I certainly want things to move faster). Also, thanks for the review! |
Place expressions do not really create temporaries, so they will not create significant drops. For example, the following code snippet is quite good (#8963):
Also, the previous logic thinks that references like
&MutexGuard<_>
/Ref<'_, MutexGuard<'_, _>>
have significant drops, which is simply not true, so it is fixed together in this PR.Fixes #8963
Fixes #9072
changelog: [
significant_drop_in_scrutinee
]: Fix false positives due to false drops of place expressions.r? @blyxyas