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