4
4
5
5
use std:: assert_matches:: debug_assert_matches;
6
6
use std:: borrow:: Cow ;
7
- use std:: iter;
8
7
use std:: ops:: { ControlFlow , Range } ;
9
8
10
9
use hir:: def:: { CtorKind , DefKind } ;
@@ -20,7 +19,7 @@ use rustc_type_ir::TyKind::*;
20
19
use rustc_type_ir:: visit:: TypeVisitableExt ;
21
20
use rustc_type_ir:: { self as ir, BoundVar , CollectAndApply , DynKind } ;
22
21
use tracing:: instrument;
23
- use ty:: util:: { AsyncDropGlueMorphology , IntTypeExt } ;
22
+ use ty:: util:: IntTypeExt ;
24
23
25
24
use super :: GenericParamDefKind ;
26
25
use crate :: infer:: canonical:: Canonical ;
@@ -1018,10 +1017,6 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
1018
1017
self . discriminant_ty ( interner)
1019
1018
}
1020
1019
1021
- fn async_destructor_ty ( self , interner : TyCtxt < ' tcx > ) -> Ty < ' tcx > {
1022
- self . async_destructor_ty ( interner)
1023
- }
1024
-
1025
1020
fn has_unsafe_fields ( self ) -> bool {
1026
1021
Ty :: has_unsafe_fields ( self )
1027
1022
}
@@ -1548,125 +1543,6 @@ impl<'tcx> Ty<'tcx> {
1548
1543
}
1549
1544
}
1550
1545
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
-
1670
1546
/// Returns the type of metadata for (potentially wide) pointers to this type,
1671
1547
/// or the struct tail if the metadata type cannot be determined.
1672
1548
pub fn ptr_metadata_ty_or_tail (
0 commit comments