-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #97962 - eholk:drop-tracking-must-not-suspend, r=cjgi…
…llot Make must_not_suspend lint see through references when drop tracking is enabled 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](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``
- Loading branch information
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 | ||
|