-
Notifications
You must be signed in to change notification settings - Fork 1.6k
significant_drop_in_scrutinee
: Trigger lint only if lifetime allows early significant drop
#12740
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 @flip1995 (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 (
|
☔ The latest upstream changes (presumably #12745) made this pull request unmergeable. Please resolve the merge conflicts. |
I think those are really valuable changes, but won't get to reviewing those for quite a long time, so re-assigning r? clippy |
Hi @lrh2000, thanks for the contribution! I've looked at it and nothing triggers my alerts, but we'd prefer if you could split this PR into multiple others. This would help both in the review & merging process and with bisecting future possible bugs. Thanksies for your contribution! ❤️ |
Hi @blyxyas, thank you for your comment and advice. I am willing to do that. I plan to use three PRs to cover those three changelogs. (Maybe we can have more, like one PR for each commit, but I think there's a tradeoff.)
So this PR will only cover the second changelog. I'll temporarily mark it as a draft until the first PR (#12764) is merged. Since all these changes are in one file, they must be merged one at a time, or else there will be a bunch of conflicts to resolve (and break unit tests that depend on multiple fixes or features). |
☔ The latest upstream changes (presumably #12764) made this pull request unmergeable. Please resolve the merge conflicts. |
OK, now this PR contains only one commit "Trigger lint only if lifetime allows early significant drop". This commit should be atomic enough to be reviewed separately. I've updated the PR description accordingly. |
☔ The latest upstream changes (presumably #12813) made this pull request unmergeable. Please resolve the merge conflicts. |
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, just a mini-nit
struct FoundSigDrop { | ||
found_span: Span, | ||
is_unit_return_val: bool, | ||
lint_suggestion: LintSuggestion, | ||
peel_ref_times: Option<usize>, |
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.
I think that changing this to just an usize
would be simpler
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.
Actually, it does have some effect on the error messages, as shown in the diff.
But IMO either the old or the new error messages are fine, so it might be better to remove the Option<_>
to avoid unnecessary confusion.
@bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
`significant_drop_in_scrutinee`: Trigger lint also for scrutinees in `while let` and `if let` This lint should also work for `if let` and `while let`, so this PR makes it actually work. For `while let`, I can't think of any reason why this lint shouldn't be enabled. The only problem is that the lint suggests moving the significant drop above the `while let`, which is clearly invalid in the case of `while let`. I don't know if this is fixable, but this PR simply disables the wrong suggestions. For `if let`, it seems that another lint called `if_let_mutex` has some overlapping functionality. But `significant_drop_in_scrutinee` is a bit stricter, as it will trigger even if the `else` branch does not try to lock the same mutex. changelog: [`significant_drop_in_scrutinee`]: Trigger lint also for scrutinees in `while let` and `if let`. r? `@blyxyas` (the third PR as promised in #12740 (comment), thanks for your review!)
`significant_drop_in_scrutinee`: Trigger lint also for scrutinees in `while let` and `if let` This lint should also work for `if let` and `while let`, so this PR makes it actually work. For `while let`, I can't think of any reason why this lint shouldn't be enabled. The only problem is that the lint suggests moving the significant drop above the `while let`, which is clearly invalid in the case of `while let`. I don't know if this is fixable, but this PR simply disables the wrong suggestions. For `if let`, it seems that another lint called `if_let_mutex` has some overlapping functionality. But `significant_drop_in_scrutinee` is a bit stricter, as it will trigger even if the `else` branch does not try to lock the same mutex. changelog: [`significant_drop_in_scrutinee`]: Trigger lint also for scrutinees in `while let` and `if let`. r? `@blyxyas` (the third PR as promised in #12740 (comment), thanks for your review!)
I want to argue that the following code snippet should not trigger
significant_drop_in_scrutinee
(#8987). The iterator holds a reference to the locked data, so it is expected that the mutex guard must be alive until the entire loop is finished.However, the lint should be triggered when we clone the vector. In this case, the iterator does not hold any reference to the locked data.
Unfortunately, it seems that regions on the types of local variables are mostly erased (
ReErased
) in the late lint pass. So it is hard to tell if the final expression has a lifetime relevant to the value with a significant drop.In this PR, I try to make a best-effort guess based on the function signatures. To avoid false positives, no lint is issued if the result is uncertain. I'm not sure if this is acceptable or not, so any comments are welcome.
Fixes #8987
changelog: [
significant_drop_in_scrutinee
]: Trigger lint only if lifetime allows early significant drop.r? @flip1995