From 24a24ec6ba24bfe5e0980d22f585c98a608ec701 Mon Sep 17 00:00:00 2001 From: zetanumbers Date: Tue, 13 Feb 2024 12:31:41 +0300 Subject: Add simple async drop glue generation Explainer: https://zetanumbers.github.io/book/async-drop-design.html https://github.com/rust-lang/rust/pull/121801 --- compiler/rustc_ty_utils/src/instance.rs | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'compiler/rustc_ty_utils/src/instance.rs') diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index a8f9afb87dd..3a18f4d0939 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -54,6 +54,47 @@ fn resolve_instance<'tcx>( debug!(" => trivial drop glue"); ty::InstanceDef::DropGlue(def_id, None) } + } else if Some(def_id) == tcx.lang_items().async_drop_in_place_fn() { + let ty = args.type_at(0); + + match *ty.kind() { + ty::Array(..) + | ty::Slice(_) + | ty::Tuple(_) + | ty::Bool + | ty::Char + | ty::Int(_) + | ty::Uint(_) + | ty::Float(_) + | ty::Str + | ty::RawPtr(_, _) + | ty::Ref(..) + | ty::FnDef(..) + | ty::FnPtr(..) + | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) + | ty::Adt(..) + | ty::Closure(..) + | ty::CoroutineClosure(..) + | ty::CoroutineWitness(..) + | ty::Pat(..) + | ty::Never + | ty::Coroutine(..) => {} + + ty::Param(_) + | ty::Error(_) + | ty::Dynamic(..) + | ty::Alias(..) + | ty::Infer(ty::TyVar(_)) + | ty::Bound(..) + | ty::Foreign(_) + | ty::Placeholder(_) + | ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + return Ok(None); + } + } + + debug!(" => async drop glue ctor"); + ty::InstanceDef::AsyncDropGlueCtorShim(def_id, ty) } else { debug!(" => free item"); // FIXME(effects): we may want to erase the effect param if that is present on this item. -- cgit 1.4.1-3-g733a5