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 } ;
@@ -21,7 +20,7 @@ use rustc_target::spec::abi;
21
20
use rustc_type_ir:: visit:: TypeVisitableExt ;
22
21
use rustc_type_ir:: TyKind :: * ;
23
22
use rustc_type_ir:: { self as ir, BoundVar , CollectAndApply , DynKind } ;
24
- use ty:: util:: { AsyncDropGlueMorphology , IntTypeExt } ;
23
+ use ty:: util:: IntTypeExt ;
25
24
26
25
use super :: GenericParamDefKind ;
27
26
use crate :: infer:: canonical:: Canonical ;
@@ -962,10 +961,6 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
962
961
fn discriminant_ty ( self , interner : TyCtxt < ' tcx > ) -> Ty < ' tcx > {
963
962
self . discriminant_ty ( interner)
964
963
}
965
-
966
- fn async_destructor_ty ( self , interner : TyCtxt < ' tcx > ) -> Ty < ' tcx > {
967
- self . async_destructor_ty ( interner)
968
- }
969
964
}
970
965
971
966
/// Type utilities
@@ -1477,125 +1472,6 @@ impl<'tcx> Ty<'tcx> {
1477
1472
}
1478
1473
}
1479
1474
1480
- /// Returns the type of the async destructor of this type.
1481
- pub fn async_destructor_ty ( self , tcx : TyCtxt < ' tcx > ) -> Ty < ' tcx > {
1482
- match self . async_drop_glue_morphology ( tcx) {
1483
- AsyncDropGlueMorphology :: Noop => {
1484
- return Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropNoop )
1485
- . instantiate_identity ( ) ;
1486
- }
1487
- AsyncDropGlueMorphology :: DeferredDropInPlace => {
1488
- let drop_in_place =
1489
- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropDeferredDropInPlace )
1490
- . instantiate ( tcx, & [ self . into ( ) ] ) ;
1491
- return Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1492
- . instantiate ( tcx, & [ drop_in_place. into ( ) ] ) ;
1493
- }
1494
- AsyncDropGlueMorphology :: Custom => ( ) ,
1495
- }
1496
-
1497
- match * self . kind ( ) {
1498
- ty:: Param ( _) | ty:: Alias ( ..) | ty:: Infer ( ty:: TyVar ( _) ) => {
1499
- let assoc_items = tcx
1500
- . associated_item_def_ids ( tcx. require_lang_item ( LangItem :: AsyncDestruct , None ) ) ;
1501
- Ty :: new_projection ( tcx, assoc_items[ 0 ] , [ self ] )
1502
- }
1503
-
1504
- ty:: Array ( elem_ty, _) | ty:: Slice ( elem_ty) => {
1505
- let dtor = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropSlice )
1506
- . instantiate ( tcx, & [ elem_ty. into ( ) ] ) ;
1507
- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1508
- . instantiate ( tcx, & [ dtor. into ( ) ] )
1509
- }
1510
-
1511
- ty:: Adt ( adt_def, args) if adt_def. is_enum ( ) || adt_def. is_struct ( ) => self
1512
- . adt_async_destructor_ty (
1513
- tcx,
1514
- adt_def. variants ( ) . iter ( ) . map ( |v| v. fields . iter ( ) . map ( |f| f. ty ( tcx, args) ) ) ,
1515
- ) ,
1516
- ty:: Tuple ( tys) => self . adt_async_destructor_ty ( tcx, iter:: once ( tys) ) ,
1517
- ty:: Closure ( _, args) => {
1518
- self . adt_async_destructor_ty ( tcx, iter:: once ( args. as_closure ( ) . upvar_tys ( ) ) )
1519
- }
1520
- ty:: CoroutineClosure ( _, args) => self
1521
- . adt_async_destructor_ty ( tcx, iter:: once ( args. as_coroutine_closure ( ) . upvar_tys ( ) ) ) ,
1522
-
1523
- ty:: Adt ( adt_def, _) => {
1524
- assert ! ( adt_def. is_union( ) ) ;
1525
-
1526
- let surface_drop = self . surface_async_dropper_ty ( tcx) . unwrap ( ) ;
1527
-
1528
- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1529
- . instantiate ( tcx, & [ surface_drop. into ( ) ] )
1530
- }
1531
-
1532
- ty:: Bound ( ..)
1533
- | ty:: Foreign ( _)
1534
- | ty:: Placeholder ( _)
1535
- | ty:: Infer ( ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => {
1536
- bug ! ( "`async_destructor_ty` applied to unexpected type: {self:?}" )
1537
- }
1538
-
1539
- _ => bug ! ( "`async_destructor_ty` is not yet implemented for type: {self:?}" ) ,
1540
- }
1541
- }
1542
-
1543
- fn adt_async_destructor_ty < I > ( self , tcx : TyCtxt < ' tcx > , variants : I ) -> Ty < ' tcx >
1544
- where
1545
- I : Iterator + ExactSizeIterator ,
1546
- I :: Item : IntoIterator < Item = Ty < ' tcx > > ,
1547
- {
1548
- debug_assert_eq ! ( self . async_drop_glue_morphology( tcx) , AsyncDropGlueMorphology :: Custom ) ;
1549
-
1550
- let defer = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropDefer ) ;
1551
- let chain = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropChain ) ;
1552
-
1553
- let noop =
1554
- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropNoop ) . instantiate_identity ( ) ;
1555
- let either = Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropEither ) ;
1556
-
1557
- let variants_dtor = variants
1558
- . into_iter ( )
1559
- . map ( |variant| {
1560
- variant
1561
- . into_iter ( )
1562
- . map ( |ty| defer. instantiate ( tcx, & [ ty. into ( ) ] ) )
1563
- . reduce ( |acc, next| chain. instantiate ( tcx, & [ acc. into ( ) , next. into ( ) ] ) )
1564
- . unwrap_or ( noop)
1565
- } )
1566
- . reduce ( |other, matched| {
1567
- either. instantiate ( tcx, & [ other. into ( ) , matched. into ( ) , self . into ( ) ] )
1568
- } )
1569
- . unwrap ( ) ;
1570
-
1571
- let dtor = if let Some ( dropper_ty) = self . surface_async_dropper_ty ( tcx) {
1572
- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropChain )
1573
- . instantiate ( tcx, & [ dropper_ty. into ( ) , variants_dtor. into ( ) ] )
1574
- } else {
1575
- variants_dtor
1576
- } ;
1577
-
1578
- Ty :: async_destructor_combinator ( tcx, LangItem :: AsyncDropFuse )
1579
- . instantiate ( tcx, & [ dtor. into ( ) ] )
1580
- }
1581
-
1582
- fn surface_async_dropper_ty ( self , tcx : TyCtxt < ' tcx > ) -> Option < Ty < ' tcx > > {
1583
- let adt_def = self . ty_adt_def ( ) ?;
1584
- let dropper = adt_def
1585
- . async_destructor ( tcx)
1586
- . map ( |_| LangItem :: SurfaceAsyncDropInPlace )
1587
- . or_else ( || adt_def. destructor ( tcx) . map ( |_| LangItem :: AsyncDropSurfaceDropInPlace ) ) ?;
1588
- Some ( Ty :: async_destructor_combinator ( tcx, dropper) . instantiate ( tcx, & [ self . into ( ) ] ) )
1589
- }
1590
-
1591
- fn async_destructor_combinator (
1592
- tcx : TyCtxt < ' tcx > ,
1593
- lang_item : LangItem ,
1594
- ) -> ty:: EarlyBinder < ' tcx , Ty < ' tcx > > {
1595
- tcx. fn_sig ( tcx. require_lang_item ( lang_item, None ) )
1596
- . map_bound ( |fn_sig| fn_sig. output ( ) . no_bound_vars ( ) . unwrap ( ) )
1597
- }
1598
-
1599
1475
/// Returns the type of metadata for (potentially fat) pointers to this type,
1600
1476
/// or the struct tail if the metadata type cannot be determined.
1601
1477
pub fn ptr_metadata_ty_or_tail (
0 commit comments