Skip to content
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

Make must_not_suspend lint see through references when drop tracking is enabled #97962

Merged
merged 4 commits into from
Aug 18, 2022

Conversation

eholk
Copy link
Contributor

@eholk eholk commented Jun 10, 2022

See #97333.

With drop tracking enabled, sometimes values that were previously linted are now considered dropped and not linted. This change makes must_not_suspend traverse through references to still catch these values.

Unfortunately, this leads to duplicate warnings in some cases (e.g. dedup.rs), so we only use the new behavior when drop tracking is enabled.

cc @guswynn

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 10, 2022
@rust-highfive
Copy link
Collaborator

r? @cjgillot

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 10, 2022
@@ -558,6 +560,12 @@ pub fn check_must_not_suspend_ty<'tcx>(
},
)
}
// If drop tracking is enabled, we want to look through references, since the referrent
// may not be considered live across the await point.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we want to look through references when we are not in drop_tracking mode?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the PR description says

Unfortunately, this leads to duplicate warnings in some cases (e.g. dedup.rs), so we only use the new behavior when drop tracking is enabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not see that this whole function could only emit a lint.
Anyway, why does looking through references cause duplicate warnings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, I finally have time to look at this again.

Without drop tracking, we use a scope-based analysis to decide what should be considered live across an await point, while the drop tracking version is more precise. With the scope based analysis, I think what's happening is we are seeing both a &mut Umm live across the await point and an Umm live across the await point. The first one doesn't trigger the lint because we currently don't see through the reference, but we do warn on the second.

With drop tracking, we don't see the Umm but instead only see &mut Umm. In order to warn, we need to look through the reference. The reason we don't see the Umm is because drop tracking handles temporary values differently, which leads to use not considering the field in self, but only the reference to it.

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 21, 2022
@jyn514 jyn514 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 1, 2022
@eholk eholk force-pushed the drop-tracking-must-not-suspend branch from 5d61b6d to 0da8199 Compare July 29, 2022 23:00
@cjgillot
Copy link
Contributor

@eholk, what's the status of this PR? Is this still a draft?
On the review side, this looks good to me. r=me once you finish it.

@eholk eholk marked this pull request as ready for review August 16, 2022 21:55
@eholk
Copy link
Contributor Author

eholk commented Aug 16, 2022

@cjgillot I left it as a draft because I was hoping I'd come up with a better way to do it, where we could keep the behavior consistent with and without drop tracking but also not get duplicate errors. I think it's probably better to go ahead and land as-is. We can adjust the warnings easy enough in the future if needed.

@bors r=cjgillot

@bors
Copy link
Contributor

bors commented Aug 16, 2022

@eholk: 🔑 Insufficient privileges: Not in reviewers

@jyn514
Copy link
Member

jyn514 commented Aug 16, 2022

@bors r=cjgillot

@bors
Copy link
Contributor

bors commented Aug 16, 2022

📌 Commit 0da8199 has been approved by cjgillot

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 16, 2022
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this pull request Aug 17, 2022
…d, r=cjgillot

Make must_not_suspend lint see through references when drop tracking is enabled

See rust-lang#97333.

With drop tracking enabled, sometimes values that were previously linted are now considered dropped and not linted. This change makes must_not_suspend traverse through references to still catch these values.

Unfortunately, this leads to duplicate warnings in some cases (e.g. [dedup.rs](https://cs.github.com/rust-lang/rust/blob/9a74608543d499bcc7dd505e195e8bfab9447315/src/test/ui/lint/must_not_suspend/dedup.rs#L4)), so we only use the new behavior when drop tracking is enabled.

cc `@guswynn`
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 18, 2022
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#97962 (Make must_not_suspend lint see through references when drop tracking is enabled)
 - rust-lang#99966 (avoid assertion failures in try_to_scalar_int)
 - rust-lang#100637 (Improving Fuchsia rustc support documentation)
 - rust-lang#100643 (Point at a type parameter shadowing another type)
 - rust-lang#100651 (Migrations for rustc_expand transcribe.rs)
 - rust-lang#100669 (Attribute cleanups)
 - rust-lang#100670 (Fix documentation of rustc_parse::parser::Parser::parse_stmt_without_recovery)
 - rust-lang#100674 (Migrate lint reports in typeck::check_unused to LintDiagnostic)
 - rust-lang#100688 (`ty::Error` does not match other types for region constraints)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 370bf15 into rust-lang:master Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants