44
55use std:: assert_matches:: debug_assert_matches;
66use std:: borrow:: Cow ;
7- use std:: iter;
87use std:: ops:: { ControlFlow , Range } ;
98
109use hir:: def:: { CtorKind , DefKind } ;
@@ -18,7 +17,7 @@ use rustc_span::{DUMMY_SP, Span, Symbol, sym};
1817use rustc_type_ir:: TyKind :: * ;
1918use rustc_type_ir:: { self as ir, BoundVar , CollectAndApply , DynKind , TypeVisitableExt , elaborate} ;
2019use tracing:: instrument;
21- use ty:: util:: { AsyncDropGlueMorphology , IntTypeExt } ;
20+ use ty:: util:: IntTypeExt ;
2221
2322use super :: GenericParamDefKind ;
2423use crate :: infer:: canonical:: Canonical ;
@@ -1045,10 +1044,6 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
10451044 self . discriminant_ty ( interner)
10461045 }
10471046
1048- fn async_destructor_ty ( self , interner : TyCtxt < ' tcx > ) -> Ty < ' tcx > {
1049- self . async_destructor_ty ( interner)
1050- }
1051-
10521047 fn has_unsafe_fields ( self ) -> bool {
10531048 Ty :: has_unsafe_fields ( self )
10541049 }
@@ -1575,125 +1570,6 @@ impl<'tcx> Ty<'tcx> {
15751570 }
15761571 }
15771572
1578- /// Returns the type of the async destructor of this type.
1579- pub fn async_destructor_ty ( self , tcx : TyCtxt < ' tcx > ) -> Ty < ' tcx > {
1580- match self . async_drop_glue_morphology ( tcx) {
1581- AsyncDropGlueMorphology :: Noop => {
1582- return Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropNoop )
1583- . instantiate_identity ( ) ;
1584- }
1585- AsyncDropGlueMorphology :: DeferredDropInPlace => {
1586- let drop_in_place =
1587- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropDeferredDropInPlace )
1588- . instantiate ( tcx, & [ self . into ( ) ] ) ;
1589- return Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1590- . instantiate ( tcx, & [ drop_in_place. into ( ) ] ) ;
1591- }
1592- AsyncDropGlueMorphology :: Custom => ( ) ,
1593- }
1594-
1595- match * self . kind ( ) {
1596- ty:: Param ( _) | ty:: Alias ( ..) | ty:: Infer ( ty:: TyVar ( _) ) => {
1597- let assoc_items = tcx
1598- . associated_item_def_ids ( tcx. require_lang_item ( LangItem :: AsyncDestruct , None ) ) ;
1599- Ty :: new_projection ( tcx, assoc_items[ 0 ] , [ self ] )
1600- }
1601-
1602- ty:: Array ( elem_ty, _) | ty:: Slice ( elem_ty) => {
1603- let dtor = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropSlice )
1604- . instantiate ( tcx, & [ elem_ty. into ( ) ] ) ;
1605- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1606- . instantiate ( tcx, & [ dtor. into ( ) ] )
1607- }
1608-
1609- ty:: Adt ( adt_def, args) if adt_def. is_enum ( ) || adt_def. is_struct ( ) => self
1610- . adt_async_destructor_ty (
1611- tcx,
1612- adt_def. variants ( ) . iter ( ) . map ( |v| v. fields . iter ( ) . map ( |f| f. ty ( tcx, args) ) ) ,
1613- ) ,
1614- ty:: Tuple ( tys) => self . adt_async_destructor_ty ( tcx, iter:: once ( tys) ) ,
1615- ty:: Closure ( _, args) => {
1616- self . adt_async_destructor_ty ( tcx, iter:: once ( args. as_closure ( ) . upvar_tys ( ) ) )
1617- }
1618- ty:: CoroutineClosure ( _, args) => self
1619- . adt_async_destructor_ty ( tcx, iter:: once ( args. as_coroutine_closure ( ) . upvar_tys ( ) ) ) ,
1620-
1621- ty:: Adt ( adt_def, _) => {
1622- assert ! ( adt_def. is_union( ) ) ;
1623-
1624- let surface_drop = self . surface_async_dropper_ty ( tcx) . unwrap ( ) ;
1625-
1626- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1627- . instantiate ( tcx, & [ surface_drop. into ( ) ] )
1628- }
1629-
1630- ty:: Bound ( ..)
1631- | ty:: Foreign ( _)
1632- | ty:: Placeholder ( _)
1633- | ty:: Infer ( ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => {
1634- bug ! ( "`async_destructor_ty` applied to unexpected type: {self:?}" )
1635- }
1636-
1637- _ => bug ! ( "`async_destructor_ty` is not yet implemented for type: {self:?}" ) ,
1638- }
1639- }
1640-
1641- fn adt_async_destructor_ty < I > ( self , tcx : TyCtxt < ' tcx > , variants : I ) -> Ty < ' tcx >
1642- where
1643- I : Iterator + ExactSizeIterator ,
1644- I :: Item : IntoIterator < Item = Ty < ' tcx > > ,
1645- {
1646- debug_assert_eq ! ( self . async_drop_glue_morphology( tcx) , AsyncDropGlueMorphology :: Custom ) ;
1647-
1648- let defer = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropDefer ) ;
1649- let chain = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropChain ) ;
1650-
1651- let noop =
1652- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropNoop ) . instantiate_identity ( ) ;
1653- let either = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropEither ) ;
1654-
1655- let variants_dtor = variants
1656- . into_iter ( )
1657- . map ( |variant| {
1658- variant
1659- . into_iter ( )
1660- . map ( |ty| defer. instantiate ( tcx, & [ ty. into ( ) ] ) )
1661- . reduce ( |acc, next| chain. instantiate ( tcx, & [ acc. into ( ) , next. into ( ) ] ) )
1662- . unwrap_or ( noop)
1663- } )
1664- . reduce ( |other, matched| {
1665- either. instantiate ( tcx, & [ other. into ( ) , matched. into ( ) , self . into ( ) ] )
1666- } )
1667- . unwrap ( ) ;
1668-
1669- let dtor = if let Some ( dropper_ty) = self . surface_async_dropper_ty ( tcx) {
1670- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropChain )
1671- . instantiate ( tcx, & [ dropper_ty. into ( ) , variants_dtor. into ( ) ] )
1672- } else {
1673- variants_dtor
1674- } ;
1675-
1676- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1677- . instantiate ( tcx, & [ dtor. into ( ) ] )
1678- }
1679-
1680- fn surface_async_dropper_ty ( self , tcx : TyCtxt < ' tcx > ) -> Option < Ty < ' tcx > > {
1681- let adt_def = self . ty_adt_def ( ) ?;
1682- let dropper = adt_def
1683- . async_destructor ( tcx)
1684- . map ( |_| LangItem :: SurfaceAsyncDropInPlace )
1685- . or_else ( || adt_def. destructor ( tcx) . map ( |_| LangItem :: AsyncDropSurfaceDropInPlace ) ) ?;
1686- Some ( Ty :: async_destructor_combinator ( tcx, dropper) . instantiate ( tcx, & [ self . into ( ) ] ) )
1687- }
1688-
1689- fn async_destructor_combinator (
1690- tcx : TyCtxt < ' tcx > ,
1691- lang_item : LangItem ,
1692- ) -> ty:: EarlyBinder < ' tcx , Ty < ' tcx > > {
1693- tcx. fn_sig ( tcx. require_lang_item ( lang_item, None ) )
1694- . map_bound ( |fn_sig| fn_sig. output ( ) . no_bound_vars ( ) . unwrap ( ) )
1695- }
1696-
16971573 /// Returns the type of metadata for (potentially wide) pointers to this type,
16981574 /// or the struct tail if the metadata type cannot be determined.
16991575 pub fn ptr_metadata_ty_or_tail (
0 commit comments