Skip to content

Commit 688a1e9

Browse files
committed
Async drop fix for dropee from another crate (#140858)
1 parent 3ae0b2e commit 688a1e9

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ pub struct Destructor {
11841184
#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)]
11851185
pub struct AsyncDestructor {
11861186
/// The `DefId` of the `impl AsyncDrop`
1187-
pub impl_did: LocalDefId,
1187+
pub impl_did: DefId,
11881188
}
11891189

11901190
#[derive(Clone, Copy, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]

compiler/rustc_middle/src/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ impl<'tcx> TyCtxt<'tcx> {
465465
dtor_candidate = Some(impl_did);
466466
}
467467

468-
Some(ty::AsyncDestructor { impl_did: dtor_candidate? })
468+
Some(ty::AsyncDestructor { impl_did: dtor_candidate?.into() })
469469
}
470470

471471
/// Returns the set of types that are required to be alive in
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@ edition:2021
2+
3+
#![feature(async_drop)]
4+
#![allow(incomplete_features)]
5+
6+
pub struct HasDrop;
7+
impl Drop for HasDrop{
8+
fn drop(&mut self) {
9+
println!("Sync drop");
10+
}
11+
}
12+
13+
pub struct MongoDrop;
14+
impl MongoDrop {
15+
pub async fn new() -> Result<Self, HasDrop> {
16+
Ok(Self)
17+
}
18+
}
19+
impl Drop for MongoDrop{
20+
fn drop(&mut self) {
21+
println!("Sync drop");
22+
}
23+
}
24+
impl std::future::AsyncDrop for MongoDrop {
25+
async fn drop(self: std::pin::Pin<&mut Self>) {
26+
println!("Async drop");
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//@ run-pass
2+
//@ check-run-results
3+
//@ aux-build:async-drop-dep.rs
4+
//@ edition:2021
5+
6+
#![feature(async_drop)]
7+
#![allow(incomplete_features)]
8+
9+
extern crate async_drop_dep;
10+
11+
use async_drop_dep::MongoDrop;
12+
use std::pin::pin;
13+
use std::task::{Context, Poll, Waker};
14+
use std::future::Future;
15+
16+
async fn asyncdrop() {
17+
let _ = MongoDrop::new().await;
18+
}
19+
20+
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
21+
let mut fut = pin!(fut);
22+
let ctx = &mut Context::from_waker(Waker::noop());
23+
24+
loop {
25+
match fut.as_mut().poll(ctx) {
26+
Poll::Pending => {}
27+
Poll::Ready(t) => break t,
28+
}
29+
}
30+
}
31+
32+
fn main() {
33+
let _ = block_on(asyncdrop());
34+
}
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Async drop

0 commit comments

Comments
 (0)