Skip to content

Async drop fix for dropee from another crate (#140858) #141031

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ pub struct Destructor {
#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)]
pub struct AsyncDestructor {
/// The `DefId` of the `impl AsyncDrop`
pub impl_did: LocalDefId,
pub impl_did: DefId,
}

#[derive(Clone, Copy, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ impl<'tcx> TyCtxt<'tcx> {
dtor_candidate = Some(impl_did);
}

Some(ty::AsyncDestructor { impl_did: dtor_candidate? })
Some(ty::AsyncDestructor { impl_did: dtor_candidate?.into() })
}

/// Returns the set of types that are required to be alive in
Expand Down
28 changes: 28 additions & 0 deletions tests/ui/async-await/async-drop/auxiliary/async-drop-dep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//@ edition:2021

#![feature(async_drop)]
#![allow(incomplete_features)]

pub struct HasDrop;
impl Drop for HasDrop{
fn drop(&mut self) {
println!("Sync drop");
}
}

pub struct MongoDrop;
impl MongoDrop {
pub async fn new() -> Result<Self, HasDrop> {
Ok(Self)
}
}
impl Drop for MongoDrop{
fn drop(&mut self) {
println!("Sync drop");
}
}
impl std::future::AsyncDrop for MongoDrop {
async fn drop(self: std::pin::Pin<&mut Self>) {
println!("Async drop");
}
}
34 changes: 34 additions & 0 deletions tests/ui/async-await/async-drop/dependency-dropped.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//@ run-pass
//@ check-run-results
//@ aux-build:async-drop-dep.rs
//@ edition:2021

#![feature(async_drop)]
#![allow(incomplete_features)]

extern crate async_drop_dep;

use async_drop_dep::MongoDrop;
use std::pin::pin;
use std::task::{Context, Poll, Waker};
use std::future::Future;

async fn asyncdrop() {
let _ = MongoDrop::new().await;
}

pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
let mut fut = pin!(fut);
let ctx = &mut Context::from_waker(Waker::noop());

loop {
match fut.as_mut().poll(ctx) {
Poll::Pending => {}
Poll::Ready(t) => break t,
}
}
}

fn main() {
let _ = block_on(asyncdrop());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Async drop
Loading