Skip to content

async drop not work without sync drop #140696

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
Sherlock-Holo opened this issue May 6, 2025 · 0 comments
Open

async drop not work without sync drop #140696

Sherlock-Holo opened this issue May 6, 2025 · 0 comments
Labels
C-bug Category: This is a bug. F-async_drop `#![feature(async_drop)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Sherlock-Holo
Copy link

I tried this code:

#![feature(async_drop)]

use std::future::AsyncDrop;
use std::pin::Pin;

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let _st = St;
}

struct St;

impl AsyncDrop for St {
    async fn drop(self: Pin<&mut Self>) {
        println!("123");
    }
}

I expected to see this happen:

should print 123

Instead, this happened:

nothing

if try this codes

#![feature(async_drop)]

use std::future::AsyncDrop;
use std::pin::Pin;

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let _st = St;
}

struct St;

impl Drop for St {
    fn drop(&mut self) {
        println!("456")
    }
}

impl AsyncDrop for St {
    async fn drop(self: Pin<&mut Self>) {
        println!("123");
    }
}

it print 123

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (2e6882ac5 2025-05-05)
@Sherlock-Holo Sherlock-Holo added the C-bug Category: This is a bug. label May 6, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 6, 2025
@petrochenkov petrochenkov added the F-async_drop `#![feature(async_drop)]` label May 6, 2025
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-async_drop `#![feature(async_drop)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants