-
Notifications
You must be signed in to change notification settings - Fork 13.4k
AsyncDrop trait without sync Drop generates an error #142606
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
Open
azhogin
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
azhogin:azhogin/async-drop-without-sync-drop-error
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+49
−1
Open
Changes from all commits
Commits
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
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,19 @@ | ||
//@ edition: 2024 | ||
#![feature(async_drop)] | ||
#![allow(incomplete_features)] | ||
#![crate_type = "lib"] | ||
|
||
use std::future::AsyncDrop; | ||
use std::pin::Pin; | ||
|
||
async fn foo() { | ||
let _st = St; | ||
} | ||
|
||
struct St; | ||
|
||
impl AsyncDrop for St { //~ ERROR: `AsyncDrop` impl without `Drop` impl | ||
async fn drop(self: Pin<&mut Self>) { | ||
println!("123"); | ||
} | ||
} |
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,10 @@ | ||
error: `AsyncDrop` impl without `Drop` impl | ||
--> $DIR/async-without-sync.rs:15:1 | ||
| | ||
LL | impl AsyncDrop for St { | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: type implementing `AsyncDrop` trait must also implement `Drop` trait to be used in sync context and unwinds | ||
|
||
error: aborting due to 1 previous error | ||
|
Oops, something went wrong.
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.
Which "sync contexts" are currently remaining besides unwinds?
Ideally async drop should just always be called, but while it's not it would be good to list the unimplemented cases somewhere.
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.
Sync context
- any sync function, whereAsyncDrop
type is dropped inside.fn foo() { _ = Dropee::new(); }
, whereDropee
has onlyAsyncDrop
trait withoutDrop
trait.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.
Ah, I thought cases like this are already reported as errors (they should be).
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.
Yea that's an alternative to this PR (or that allows reverting this PR): error at use sites of sync drop of types that have no
Drop
impl but anAsyncDrop
impl. This has some fun implications though, as we'd need to make sure thatCopy
andAsyncDrop
also need to be mutually exclusive, just likeCopy
andDrop
are. Or more generally: any logic checking forDrop
needs to also check forAsyncDrop
and handle that.So it may be better long term to merge various things like
adt_destructor
andadt_async_destructor
to only return a singleOption
with an enum inside for either an async or a sync variant, making it easier not to forget to check both together. There are probably many other functions that need similar treatment.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.
Well, error at use sites of sync drop may help only after implementing async-drop support for unwinds. Otherwise, we still need both traits.