Skip to content

Commit 16c1c54

Browse files
committed
Auto merge of #140902 - azhogin:azhogin/async-drop-open-drop-for-adt-fix, r=oli-obk
Async drop fix for async_drop_in_place<T> layout for unspecified T Fix for #140423. Layout of `async_drop_in_place<T>::{closure}` is calculated for unspecified T from dataflow_const_prop `try_make_constant`. `@oli-obk,` do you think, it may be a better solution to add check like `if !args[0].is_fully_specialized() { return None; }` in `fn async_drop_coroutine_layout`? And could you, pls, recommend, how to implement `is_fully_specialized()` in a most simple way?
2 parents 9a7e19f + 13178c7 commit 16c1c54

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

compiler/rustc_middle/src/ty/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,9 @@ impl<'tcx> TyCtxt<'tcx> {
19241924
def_id: DefId,
19251925
args: GenericArgsRef<'tcx>,
19261926
) -> Option<&'tcx CoroutineLayout<'tcx>> {
1927+
if args[0].has_placeholders() || args[0].has_non_region_param() {
1928+
return None;
1929+
}
19271930
let instance = InstanceKind::AsyncDropGlue(def_id, Ty::new_coroutine(self, def_id, args));
19281931
self.mir_shims(instance).coroutine_layout_raw()
19291932
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ compile-flags: -Zmir-enable-passes=+DataflowConstProp
2+
//@ edition: 2021
3+
//@ build-pass
4+
#![feature(async_drop)]
5+
#![allow(incomplete_features)]
6+
7+
use std::mem::ManuallyDrop;
8+
use std::{
9+
future::async_drop_in_place,
10+
pin::{pin, Pin},
11+
};
12+
fn main() {
13+
a(b)
14+
}
15+
fn b() {}
16+
fn a<C>(d: C) {
17+
let e = pin!(ManuallyDrop::new(d));
18+
let f = unsafe { Pin::map_unchecked_mut(e, |g| &mut **g) };
19+
let h = unsafe { async_drop_in_place(f.get_unchecked_mut()) };
20+
h;
21+
}

0 commit comments

Comments
 (0)