diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 2d69a1c2b553e..dda0faa3afedd 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -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() } diff --git a/tests/ui/async-await/async-drop/open-drop-error.rs b/tests/ui/async-await/async-drop/open-drop-error.rs new file mode 100644 index 0000000000000..1d97eee521094 --- /dev/null +++ b/tests/ui/async-await/async-drop/open-drop-error.rs @@ -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(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; +}