Async drop fix for async_drop_in_place<T> layout calculated for unspecified T

This commit is contained in:
Andrew Zhogin 2025-05-11 02:21:56 +07:00 committed by Pietro Albini
parent be8721b77b
commit b166e65184
No known key found for this signature in database
GPG key ID: 3E06ABE80BAAF19C
2 changed files with 24 additions and 0 deletions

View file

@ -1924,6 +1924,9 @@ impl<'tcx> TyCtxt<'tcx> {
def_id: DefId,
args: GenericArgsRef<'tcx>,
) -> Option<&'tcx CoroutineLayout<'tcx>> {
if args[0].has_placeholders() || args[0].has_non_region_param() {
return None;
}
let instance = InstanceKind::AsyncDropGlue(def_id, Ty::new_coroutine(self, def_id, args));
self.mir_shims(instance).coroutine_layout_raw()
}

View file

@ -0,0 +1,21 @@
//@ compile-flags: -Zmir-enable-passes=+DataflowConstProp
//@ edition: 2021
//@ build-pass
#![feature(async_drop)]
#![allow(incomplete_features)]
use std::mem::ManuallyDrop;
use std::{
future::async_drop_in_place,
pin::{pin, Pin},
};
fn main() {
a(b)
}
fn b() {}
fn a<C>(d: C) {
let e = pin!(ManuallyDrop::new(d));
let f = unsafe { Pin::map_unchecked_mut(e, |g| &mut **g) };
let h = unsafe { async_drop_in_place(f.get_unchecked_mut()) };
h;
}