Skip to content

segmentation fault when using async_drop feature #142572

Open
@Sherlock-Holo

Description

@Sherlock-Holo

I tried this code:

lib.rs

#![feature(async_drop)]

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

use tokio::time;

pub async fn run() {
    let _st = St(Duration::from_secs(1));
}

pub struct St(Duration);

impl Drop for St {
    fn drop(&mut self) {}
}

impl AsyncDrop for St {
    async fn drop(self: Pin<&mut Self>) {
        time::sleep(self.0).await;

        println!("async drop");
    }
}

main.rs

#[tokio::main]
async fn main() {
    ttt::run().await;
}

Cargo.toml

[package]
name = "ttt"
version = "0.1.0"
edition = "2024"

[dependencies]
tokio = { version = "1.45.1", features = ["rt", "macros", "time", "rt-multi-thread"] }

I expected to see this happen: exit with 0

Instead, this happened:

[1]    4076757 segmentation fault (core dumped)  ./target/debug/ttt

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (586ad391f 2025-06-15)
binary: rustc
commit-hash: 586ad391f5ee4519acc7cae340e34673bae762b1
commit-date: 2025-06-15
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitC-bugCategory: This is a bug.F-async_drop`#![feature(async_drop)]`I-miscompileIssue: Correct Rust code lowers to incorrect machine codeI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions