@@ -6,7 +6,7 @@ use serde::Serialize;
6
6
use super :: mir:: { Body , Mutability , Safety } ;
7
7
use super :: { DefId , Error , Symbol , with} ;
8
8
use crate :: abi:: { FnAbi , Layout } ;
9
- use crate :: crate_def:: { CrateDef , CrateDefType } ;
9
+ use crate :: crate_def:: { CrateDef , CrateDefItems , CrateDefType } ;
10
10
use crate :: mir:: alloc:: { AllocId , read_target_int, read_target_uint} ;
11
11
use crate :: mir:: mono:: StaticDef ;
12
12
use crate :: target:: MachineInfo ;
@@ -910,6 +910,10 @@ crate_def! {
910
910
pub TraitDef ;
911
911
}
912
912
913
+ impl_crate_def_items ! {
914
+ TraitDef ;
915
+ }
916
+
913
917
impl TraitDef {
914
918
pub fn declaration ( trait_def : & TraitDef ) -> TraitDecl {
915
919
with ( |cx| cx. trait_decl ( trait_def) )
@@ -932,6 +936,10 @@ crate_def! {
932
936
pub ImplDef ;
933
937
}
934
938
939
+ impl_crate_def_items ! {
940
+ ImplDef ;
941
+ }
942
+
935
943
impl ImplDef {
936
944
/// Retrieve information about this implementation.
937
945
pub fn trait_impl ( & self ) -> ImplTrait {
@@ -1555,3 +1563,60 @@ index_impl!(Span);
1555
1563
pub struct VariantIdx ( usize ) ;
1556
1564
1557
1565
index_impl ! ( VariantIdx ) ;
1566
+
1567
+ crate_def ! {
1568
+ /// Hold infomation about an Opaque definition, particularly useful in `RPITIT`.
1569
+ #[ derive( Serialize ) ]
1570
+ pub OpaqueDef ;
1571
+ }
1572
+
1573
+ crate_def ! {
1574
+ #[ derive( Serialize ) ]
1575
+ pub AssocDef ;
1576
+ }
1577
+
1578
+ #[ derive( Clone , Debug , Eq , PartialEq , Serialize ) ]
1579
+ pub struct AssocItem {
1580
+ pub def_id : AssocDef ,
1581
+ pub name : Symbol ,
1582
+ pub kind : AssocKind ,
1583
+ pub container : AssocItemContainer ,
1584
+
1585
+ /// If this is an item in an impl of a trait then this is the `DefId` of
1586
+ /// the associated item on the trait that this implements.
1587
+ pub trait_item_def_id : Option < AssocDef > ,
1588
+
1589
+ /// Whether this is a method with an explicit self
1590
+ /// as its first parameter, allowing method calls.
1591
+ pub fn_has_self_parameter : bool ,
1592
+
1593
+ /// `Some` if the associated item (an associated type) comes from the
1594
+ /// return-position `impl Trait` in trait desugaring. The `ImplTraitInTraitData`
1595
+ /// provides additional information about its source.
1596
+ pub opt_rpitit_info : Option < ImplTraitInTraitData > ,
1597
+ }
1598
+
1599
+ #[ derive( Clone , Debug , Eq , PartialEq , Serialize ) ]
1600
+ pub enum AssocKind {
1601
+ Const ,
1602
+ Fn ,
1603
+ Type ,
1604
+ }
1605
+
1606
+ #[ derive( Clone , Debug , Eq , PartialEq , Serialize ) ]
1607
+ pub enum AssocItemContainer {
1608
+ Trait ,
1609
+ Impl ,
1610
+ }
1611
+
1612
+ #[ derive( Clone , Copy , PartialEq , Eq , Debug , Hash , Serialize ) ]
1613
+ pub enum ImplTraitInTraitData {
1614
+ Trait { fn_def_id : FnDef , opaque_def_id : OpaqueDef } ,
1615
+ Impl { fn_def_id : FnDef } ,
1616
+ }
1617
+
1618
+ impl AssocItem {
1619
+ pub fn is_impl_trait_in_trait ( & self ) -> bool {
1620
+ self . opt_rpitit_info . is_some ( )
1621
+ }
1622
+ }
0 commit comments