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 } ;
@@ -20,7 +19,7 @@ use rustc_type_ir::TyKind::*;
2019use rustc_type_ir:: visit:: TypeVisitableExt ;
2120use rustc_type_ir:: { self as ir, BoundVar , CollectAndApply , DynKind } ;
2221use tracing:: instrument;
23- use ty:: util:: { AsyncDropGlueMorphology , IntTypeExt } ;
22+ use ty:: util:: IntTypeExt ;
2423
2524use super :: GenericParamDefKind ;
2625use crate :: infer:: canonical:: Canonical ;
@@ -1018,10 +1017,6 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
10181017 self . discriminant_ty ( interner)
10191018 }
10201019
1021- fn async_destructor_ty ( self , interner : TyCtxt < ' tcx > ) -> Ty < ' tcx > {
1022- self . async_destructor_ty ( interner)
1023- }
1024-
10251020 fn has_unsafe_fields ( self ) -> bool {
10261021 Ty :: has_unsafe_fields ( self )
10271022 }
@@ -1548,125 +1543,6 @@ impl<'tcx> Ty<'tcx> {
15481543 }
15491544 }
15501545
1551- /// Returns the type of the async destructor of this type.
1552- pub fn async_destructor_ty ( self , tcx : TyCtxt < ' tcx > ) -> Ty < ' tcx > {
1553- match self . async_drop_glue_morphology ( tcx) {
1554- AsyncDropGlueMorphology :: Noop => {
1555- return Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropNoop )
1556- . instantiate_identity ( ) ;
1557- }
1558- AsyncDropGlueMorphology :: DeferredDropInPlace => {
1559- let drop_in_place =
1560- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropDeferredDropInPlace )
1561- . instantiate ( tcx, & [ self . into ( ) ] ) ;
1562- return Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1563- . instantiate ( tcx, & [ drop_in_place. into ( ) ] ) ;
1564- }
1565- AsyncDropGlueMorphology :: Custom => ( ) ,
1566- }
1567-
1568- match * self . kind ( ) {
1569- ty:: Param ( _) | ty:: Alias ( ..) | ty:: Infer ( ty:: TyVar ( _) ) => {
1570- let assoc_items = tcx
1571- . associated_item_def_ids ( tcx. require_lang_item ( LangItem :: AsyncDestruct , None ) ) ;
1572- Ty :: new_projection ( tcx, assoc_items[ 0 ] , [ self ] )
1573- }
1574-
1575- ty:: Array ( elem_ty, _) | ty:: Slice ( elem_ty) => {
1576- let dtor = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropSlice )
1577- . instantiate ( tcx, & [ elem_ty. into ( ) ] ) ;
1578- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1579- . instantiate ( tcx, & [ dtor. into ( ) ] )
1580- }
1581-
1582- ty:: Adt ( adt_def, args) if adt_def. is_enum ( ) || adt_def. is_struct ( ) => self
1583- . adt_async_destructor_ty (
1584- tcx,
1585- adt_def. variants ( ) . iter ( ) . map ( |v| v. fields . iter ( ) . map ( |f| f. ty ( tcx, args) ) ) ,
1586- ) ,
1587- ty:: Tuple ( tys) => self . adt_async_destructor_ty ( tcx, iter:: once ( tys) ) ,
1588- ty:: Closure ( _, args) => {
1589- self . adt_async_destructor_ty ( tcx, iter:: once ( args. as_closure ( ) . upvar_tys ( ) ) )
1590- }
1591- ty:: CoroutineClosure ( _, args) => self
1592- . adt_async_destructor_ty ( tcx, iter:: once ( args. as_coroutine_closure ( ) . upvar_tys ( ) ) ) ,
1593-
1594- ty:: Adt ( adt_def, _) => {
1595- assert ! ( adt_def. is_union( ) ) ;
1596-
1597- let surface_drop = self . surface_async_dropper_ty ( tcx) . unwrap ( ) ;
1598-
1599- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1600- . instantiate ( tcx, & [ surface_drop. into ( ) ] )
1601- }
1602-
1603- ty:: Bound ( ..)
1604- | ty:: Foreign ( _)
1605- | ty:: Placeholder ( _)
1606- | ty:: Infer ( ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => {
1607- bug ! ( "`async_destructor_ty` applied to unexpected type: {self:?}" )
1608- }
1609-
1610- _ => bug ! ( "`async_destructor_ty` is not yet implemented for type: {self:?}" ) ,
1611- }
1612- }
1613-
1614- fn adt_async_destructor_ty < I > ( self , tcx : TyCtxt < ' tcx > , variants : I ) -> Ty < ' tcx >
1615- where
1616- I : Iterator + ExactSizeIterator ,
1617- I :: Item : IntoIterator < Item = Ty < ' tcx > > ,
1618- {
1619- debug_assert_eq ! ( self . async_drop_glue_morphology( tcx) , AsyncDropGlueMorphology :: Custom ) ;
1620-
1621- let defer = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropDefer ) ;
1622- let chain = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropChain ) ;
1623-
1624- let noop =
1625- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropNoop ) . instantiate_identity ( ) ;
1626- let either = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropEither ) ;
1627-
1628- let variants_dtor = variants
1629- . into_iter ( )
1630- . map ( |variant| {
1631- variant
1632- . into_iter ( )
1633- . map ( |ty| defer. instantiate ( tcx, & [ ty. into ( ) ] ) )
1634- . reduce ( |acc, next| chain. instantiate ( tcx, & [ acc. into ( ) , next. into ( ) ] ) )
1635- . unwrap_or ( noop)
1636- } )
1637- . reduce ( |other, matched| {
1638- either. instantiate ( tcx, & [ other. into ( ) , matched. into ( ) , self . into ( ) ] )
1639- } )
1640- . unwrap ( ) ;
1641-
1642- let dtor = if let Some ( dropper_ty) = self . surface_async_dropper_ty ( tcx) {
1643- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropChain )
1644- . instantiate ( tcx, & [ dropper_ty. into ( ) , variants_dtor. into ( ) ] )
1645- } else {
1646- variants_dtor
1647- } ;
1648-
1649- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1650- . instantiate ( tcx, & [ dtor. into ( ) ] )
1651- }
1652-
1653- fn surface_async_dropper_ty ( self , tcx : TyCtxt < ' tcx > ) -> Option < Ty < ' tcx > > {
1654- let adt_def = self . ty_adt_def ( ) ?;
1655- let dropper = adt_def
1656- . async_destructor ( tcx)
1657- . map ( |_| LangItem :: SurfaceAsyncDropInPlace )
1658- . or_else ( || adt_def. destructor ( tcx) . map ( |_| LangItem :: AsyncDropSurfaceDropInPlace ) ) ?;
1659- Some ( Ty :: async_destructor_combinator ( tcx, dropper) . instantiate ( tcx, & [ self . into ( ) ] ) )
1660- }
1661-
1662- fn async_destructor_combinator (
1663- tcx : TyCtxt < ' tcx > ,
1664- lang_item : LangItem ,
1665- ) -> ty:: EarlyBinder < ' tcx , Ty < ' tcx > > {
1666- tcx. fn_sig ( tcx. require_lang_item ( lang_item, None ) )
1667- . map_bound ( |fn_sig| fn_sig. output ( ) . no_bound_vars ( ) . unwrap ( ) )
1668- }
1669-
16701546 /// Returns the type of metadata for (potentially wide) pointers to this type,
16711547 /// or the struct tail if the metadata type cannot be determined.
16721548 pub fn ptr_metadata_ty_or_tail (
0 commit comments