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 }
@@ -1559,125 +1554,6 @@ impl<'tcx> Ty<'tcx> {
15591554 }
15601555 }
15611556
1562- /// Returns the type of the async destructor of this type.
1563- pub fn async_destructor_ty ( self , tcx : TyCtxt < ' tcx > ) -> Ty < ' tcx > {
1564- match self . async_drop_glue_morphology ( tcx) {
1565- AsyncDropGlueMorphology :: Noop => {
1566- return Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropNoop )
1567- . instantiate_identity ( ) ;
1568- }
1569- AsyncDropGlueMorphology :: DeferredDropInPlace => {
1570- let drop_in_place =
1571- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropDeferredDropInPlace )
1572- . instantiate ( tcx, & [ self . into ( ) ] ) ;
1573- return Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1574- . instantiate ( tcx, & [ drop_in_place. into ( ) ] ) ;
1575- }
1576- AsyncDropGlueMorphology :: Custom => ( ) ,
1577- }
1578-
1579- match * self . kind ( ) {
1580- ty:: Param ( _) | ty:: Alias ( ..) | ty:: Infer ( ty:: TyVar ( _) ) => {
1581- let assoc_items = tcx
1582- . associated_item_def_ids ( tcx. require_lang_item ( LangItem :: AsyncDestruct , None ) ) ;
1583- Ty :: new_projection ( tcx, assoc_items[ 0 ] , [ self ] )
1584- }
1585-
1586- ty:: Array ( elem_ty, _) | ty:: Slice ( elem_ty) => {
1587- let dtor = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropSlice )
1588- . instantiate ( tcx, & [ elem_ty. into ( ) ] ) ;
1589- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1590- . instantiate ( tcx, & [ dtor. into ( ) ] )
1591- }
1592-
1593- ty:: Adt ( adt_def, args) if adt_def. is_enum ( ) || adt_def. is_struct ( ) => self
1594- . adt_async_destructor_ty (
1595- tcx,
1596- adt_def. variants ( ) . iter ( ) . map ( |v| v. fields . iter ( ) . map ( |f| f. ty ( tcx, args) ) ) ,
1597- ) ,
1598- ty:: Tuple ( tys) => self . adt_async_destructor_ty ( tcx, iter:: once ( tys) ) ,
1599- ty:: Closure ( _, args) => {
1600- self . adt_async_destructor_ty ( tcx, iter:: once ( args. as_closure ( ) . upvar_tys ( ) ) )
1601- }
1602- ty:: CoroutineClosure ( _, args) => self
1603- . adt_async_destructor_ty ( tcx, iter:: once ( args. as_coroutine_closure ( ) . upvar_tys ( ) ) ) ,
1604-
1605- ty:: Adt ( adt_def, _) => {
1606- assert ! ( adt_def. is_union( ) ) ;
1607-
1608- let surface_drop = self . surface_async_dropper_ty ( tcx) . unwrap ( ) ;
1609-
1610- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1611- . instantiate ( tcx, & [ surface_drop. into ( ) ] )
1612- }
1613-
1614- ty:: Bound ( ..)
1615- | ty:: Foreign ( _)
1616- | ty:: Placeholder ( _)
1617- | ty:: Infer ( ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => {
1618- bug ! ( "`async_destructor_ty` applied to unexpected type: {self:?}" )
1619- }
1620-
1621- _ => bug ! ( "`async_destructor_ty` is not yet implemented for type: {self:?}" ) ,
1622- }
1623- }
1624-
1625- fn adt_async_destructor_ty < I > ( self , tcx : TyCtxt < ' tcx > , variants : I ) -> Ty < ' tcx >
1626- where
1627- I : Iterator + ExactSizeIterator ,
1628- I :: Item : IntoIterator < Item = Ty < ' tcx > > ,
1629- {
1630- debug_assert_eq ! ( self . async_drop_glue_morphology( tcx) , AsyncDropGlueMorphology :: Custom ) ;
1631-
1632- let defer = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropDefer ) ;
1633- let chain = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropChain ) ;
1634-
1635- let noop =
1636- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropNoop ) . instantiate_identity ( ) ;
1637- let either = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropEither ) ;
1638-
1639- let variants_dtor = variants
1640- . into_iter ( )
1641- . map ( |variant| {
1642- variant
1643- . into_iter ( )
1644- . map ( |ty| defer. instantiate ( tcx, & [ ty. into ( ) ] ) )
1645- . reduce ( |acc, next| chain. instantiate ( tcx, & [ acc. into ( ) , next. into ( ) ] ) )
1646- . unwrap_or ( noop)
1647- } )
1648- . reduce ( |other, matched| {
1649- either. instantiate ( tcx, & [ other. into ( ) , matched. into ( ) , self . into ( ) ] )
1650- } )
1651- . unwrap ( ) ;
1652-
1653- let dtor = if let Some ( dropper_ty) = self . surface_async_dropper_ty ( tcx) {
1654- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropChain )
1655- . instantiate ( tcx, & [ dropper_ty. into ( ) , variants_dtor. into ( ) ] )
1656- } else {
1657- variants_dtor
1658- } ;
1659-
1660- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1661- . instantiate ( tcx, & [ dtor. into ( ) ] )
1662- }
1663-
1664- fn surface_async_dropper_ty ( self , tcx : TyCtxt < ' tcx > ) -> Option < Ty < ' tcx > > {
1665- let adt_def = self . ty_adt_def ( ) ?;
1666- let dropper = adt_def
1667- . async_destructor ( tcx)
1668- . map ( |_| LangItem :: SurfaceAsyncDropInPlace )
1669- . or_else ( || adt_def. destructor ( tcx) . map ( |_| LangItem :: AsyncDropSurfaceDropInPlace ) ) ?;
1670- Some ( Ty :: async_destructor_combinator ( tcx, dropper) . instantiate ( tcx, & [ self . into ( ) ] ) )
1671- }
1672-
1673- fn async_destructor_combinator (
1674- tcx : TyCtxt < ' tcx > ,
1675- lang_item : LangItem ,
1676- ) -> ty:: EarlyBinder < ' tcx , Ty < ' tcx > > {
1677- tcx. fn_sig ( tcx. require_lang_item ( lang_item, None ) )
1678- . map_bound ( |fn_sig| fn_sig. output ( ) . no_bound_vars ( ) . unwrap ( ) )
1679- }
1680-
16811557 /// Returns the type of metadata for (potentially wide) pointers to this type,
16821558 /// or the struct tail if the metadata type cannot be determined.
16831559 pub fn ptr_metadata_ty_or_tail (
0 commit comments