@@ -25,7 +25,7 @@ use std::assert_matches::debug_assert_matches;
2525use std:: borrow:: Cow ;
2626use std:: iter;
2727use std:: ops:: { ControlFlow , Range } ;
28- use ty:: util:: IntTypeExt ;
28+ use ty:: util:: { AsyncDropGlueMorphology , IntTypeExt } ;
2929
3030use rustc_type_ir:: TyKind :: * ;
3131use rustc_type_ir:: { self as ir, BoundVar , CollectAndApply , DynKind } ;
@@ -1951,11 +1951,22 @@ impl<'tcx> Ty<'tcx> {
19511951 }
19521952
19531953 /// Returns the type of the async destructor of this type.
1954- pub fn async_destructor_ty ( self , tcx : TyCtxt < ' tcx > , param_env : ParamEnv < ' tcx > ) -> Ty < ' tcx > {
1955- if self . is_async_destructor_noop ( tcx, param_env) || matches ! ( self . kind( ) , ty:: Error ( _) ) {
1956- return Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropNoop )
1957- . instantiate_identity ( ) ;
1954+ pub fn async_destructor_ty ( self , tcx : TyCtxt < ' tcx > ) -> Ty < ' tcx > {
1955+ match self . async_drop_glue_morphology ( tcx) {
1956+ AsyncDropGlueMorphology :: Noop => {
1957+ return Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropNoop )
1958+ . instantiate_identity ( ) ;
1959+ }
1960+ AsyncDropGlueMorphology :: DeferredDropInPlace => {
1961+ let drop_in_place =
1962+ Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropDeferredDropInPlace )
1963+ . instantiate ( tcx, & [ self . into ( ) ] ) ;
1964+ return Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1965+ . instantiate ( tcx, & [ drop_in_place. into ( ) ] ) ;
1966+ }
1967+ AsyncDropGlueMorphology :: Custom => ( ) ,
19581968 }
1969+
19591970 match * self . kind ( ) {
19601971 ty:: Param ( _) | ty:: Alias ( ..) | ty:: Infer ( ty:: TyVar ( _) ) => {
19611972 let assoc_items = tcx
@@ -1974,24 +1985,18 @@ impl<'tcx> Ty<'tcx> {
19741985 . adt_async_destructor_ty (
19751986 tcx,
19761987 adt_def. variants ( ) . iter ( ) . map ( |v| v. fields . iter ( ) . map ( |f| f. ty ( tcx, args) ) ) ,
1977- param_env,
19781988 ) ,
1979- ty:: Tuple ( tys) => self . adt_async_destructor_ty ( tcx, iter:: once ( tys) , param_env) ,
1980- ty:: Closure ( _, args) => self . adt_async_destructor_ty (
1981- tcx,
1982- iter:: once ( args. as_closure ( ) . upvar_tys ( ) ) ,
1983- param_env,
1984- ) ,
1985- ty:: CoroutineClosure ( _, args) => self . adt_async_destructor_ty (
1986- tcx,
1987- iter:: once ( args. as_coroutine_closure ( ) . upvar_tys ( ) ) ,
1988- param_env,
1989- ) ,
1989+ ty:: Tuple ( tys) => self . adt_async_destructor_ty ( tcx, iter:: once ( tys) ) ,
1990+ ty:: Closure ( _, args) => {
1991+ self . adt_async_destructor_ty ( tcx, iter:: once ( args. as_closure ( ) . upvar_tys ( ) ) )
1992+ }
1993+ ty:: CoroutineClosure ( _, args) => self
1994+ . adt_async_destructor_ty ( tcx, iter:: once ( args. as_coroutine_closure ( ) . upvar_tys ( ) ) ) ,
19901995
19911996 ty:: Adt ( adt_def, _) => {
19921997 assert ! ( adt_def. is_union( ) ) ;
19931998
1994- let surface_drop = self . surface_async_dropper_ty ( tcx, param_env ) . unwrap ( ) ;
1999+ let surface_drop = self . surface_async_dropper_ty ( tcx) . unwrap ( ) ;
19952000
19962001 Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
19972002 . instantiate ( tcx, & [ surface_drop. into ( ) ] )
@@ -2008,17 +2013,12 @@ impl<'tcx> Ty<'tcx> {
20082013 }
20092014 }
20102015
2011- fn adt_async_destructor_ty < I > (
2012- self ,
2013- tcx : TyCtxt < ' tcx > ,
2014- variants : I ,
2015- param_env : ParamEnv < ' tcx > ,
2016- ) -> Ty < ' tcx >
2016+ fn adt_async_destructor_ty < I > ( self , tcx : TyCtxt < ' tcx > , variants : I ) -> Ty < ' tcx >
20172017 where
20182018 I : Iterator + ExactSizeIterator ,
20192019 I :: Item : IntoIterator < Item = Ty < ' tcx > > ,
20202020 {
2021- debug_assert ! ( ! self . is_async_destructor_noop ( tcx, param_env ) ) ;
2021+ debug_assert_eq ! ( self . async_drop_glue_morphology ( tcx) , AsyncDropGlueMorphology :: Custom ) ;
20222022
20232023 let defer = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropDefer ) ;
20242024 let chain = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropChain ) ;
@@ -2041,7 +2041,7 @@ impl<'tcx> Ty<'tcx> {
20412041 } )
20422042 . unwrap ( ) ;
20432043
2044- let dtor = if let Some ( dropper_ty) = self . surface_async_dropper_ty ( tcx, param_env ) {
2044+ let dtor = if let Some ( dropper_ty) = self . surface_async_dropper_ty ( tcx) {
20452045 Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropChain )
20462046 . instantiate ( tcx, & [ dropper_ty. into ( ) , variants_dtor. into ( ) ] )
20472047 } else {
@@ -2052,21 +2052,13 @@ impl<'tcx> Ty<'tcx> {
20522052 . instantiate ( tcx, & [ dtor. into ( ) ] )
20532053 }
20542054
2055- fn surface_async_dropper_ty (
2056- self ,
2057- tcx : TyCtxt < ' tcx > ,
2058- param_env : ParamEnv < ' tcx > ,
2059- ) -> Option < Ty < ' tcx > > {
2060- if self . has_surface_async_drop ( tcx, param_env) {
2061- Some ( LangItem :: SurfaceAsyncDropInPlace )
2062- } else if self . has_surface_drop ( tcx, param_env) {
2063- Some ( LangItem :: AsyncDropSurfaceDropInPlace )
2064- } else {
2065- None
2066- }
2067- . map ( |dropper| {
2068- Ty :: async_destructor_combinator ( tcx, dropper) . instantiate ( tcx, & [ self . into ( ) ] )
2069- } )
2055+ fn surface_async_dropper_ty ( self , tcx : TyCtxt < ' tcx > ) -> Option < Ty < ' tcx > > {
2056+ let adt_def = self . ty_adt_def ( ) ?;
2057+ let dropper = adt_def
2058+ . async_destructor ( tcx)
2059+ . map ( |_| LangItem :: SurfaceAsyncDropInPlace )
2060+ . or_else ( || adt_def. destructor ( tcx) . map ( |_| LangItem :: AsyncDropSurfaceDropInPlace ) ) ?;
2061+ Some ( Ty :: async_destructor_combinator ( tcx, dropper) . instantiate ( tcx, & [ self . into ( ) ] ) )
20702062 }
20712063
20722064 fn async_destructor_combinator (
0 commit comments