-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Make must_not_suspend lint see through references when drop tracking is enabled #97962
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// edition:2018 | ||
// compile-flags: -Zdrop-tracking | ||
#![feature(must_not_suspend)] | ||
#![deny(must_not_suspend)] | ||
|
||
#[must_not_suspend = "You gotta use Umm's, ya know?"] | ||
struct Umm { | ||
i: i64 | ||
} | ||
|
||
struct Bar { | ||
u: Umm, | ||
} | ||
|
||
async fn other() {} | ||
|
||
impl Bar { | ||
async fn uhoh(&mut self) { | ||
let guard = &mut self.u; //~ ERROR `Umm` held across | ||
|
||
other().await; | ||
|
||
*guard = Umm { | ||
i: 2 | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/ui/lint/must_not_suspend/ref-drop-tracking.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error: reference to `Umm` held across a suspend point, but should not be | ||
--> $DIR/ref-drop-tracking.rs:19:13 | ||
| | ||
LL | let guard = &mut self.u; | ||
| ^^^^^ | ||
LL | | ||
LL | other().await; | ||
| ------ the value is held across this suspend point | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/ref-drop-tracking.rs:4:9 | ||
| | ||
LL | #![deny(must_not_suspend)] | ||
| ^^^^^^^^^^^^^^^^ | ||
note: You gotta use Umm's, ya know? | ||
--> $DIR/ref-drop-tracking.rs:19:13 | ||
| | ||
LL | let guard = &mut self.u; | ||
| ^^^^^ | ||
help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point | ||
--> $DIR/ref-drop-tracking.rs:19:13 | ||
| | ||
LL | let guard = &mut self.u; | ||
| ^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why don't we want to look through references when we are not in
drop_tracking
mode?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.
the PR description says
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 did not see that this whole function could only emit a lint.
Anyway, why does looking through references cause duplicate warnings?
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.
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 anUmm
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 theUmm
is because drop tracking handles temporary values differently, which leads to use not considering the field inself
, but only the reference to it.