@@ -6,7 +6,7 @@ use serde::Serialize;
66use super :: mir:: { Body , Mutability , Safety } ;
77use super :: { DefId , Error , Symbol , with} ;
88use crate :: abi:: { FnAbi , Layout } ;
9- use crate :: crate_def:: { CrateDef , CrateDefType } ;
9+ use crate :: crate_def:: { CrateDef , CrateDefItems , CrateDefType } ;
1010use crate :: mir:: alloc:: { AllocId , read_target_int, read_target_uint} ;
1111use crate :: mir:: mono:: StaticDef ;
1212use crate :: target:: MachineInfo ;
@@ -773,6 +773,15 @@ pub enum AdtKind {
773773 Struct ,
774774}
775775
776+ impl CrateDefItems for AdtDef {
777+ fn associated_items ( & self ) -> AssocItems {
778+ match & self . kind ( ) {
779+ AdtKind :: Enum | AdtKind :: Struct => with ( |cx| cx. associated_items ( self . def_id ( ) ) ) ,
780+ AdtKind :: Union => AssocItems { items : Vec :: new ( ) } ,
781+ }
782+ }
783+ }
784+
776785impl AdtDef {
777786 pub fn kind ( & self ) -> AdtKind {
778787 with ( |cx| cx. adt_kind ( * self ) )
@@ -910,6 +919,10 @@ crate_def! {
910919 pub TraitDef ;
911920}
912921
922+ impl_crate_def_items ! {
923+ TraitDef ;
924+ }
925+
913926impl TraitDef {
914927 pub fn declaration ( trait_def : & TraitDef ) -> TraitDecl {
915928 with ( |cx| cx. trait_decl ( trait_def) )
@@ -932,6 +945,10 @@ crate_def! {
932945 pub ImplDef ;
933946}
934947
948+ impl_crate_def_items ! {
949+ ImplDef ;
950+ }
951+
935952impl ImplDef {
936953 /// Retrieve information about this implementation.
937954 pub fn trait_impl ( & self ) -> ImplTrait {
@@ -1555,3 +1572,65 @@ index_impl!(Span);
15551572pub struct VariantIdx ( usize ) ;
15561573
15571574index_impl ! ( VariantIdx ) ;
1575+
1576+ #[ derive( Clone , Debug , Eq , PartialEq , Serialize ) ]
1577+ pub struct AssocItems {
1578+ pub items : Vec < ( Symbol , AssocItem ) > ,
1579+ }
1580+
1581+ crate_def ! {
1582+ /// Hold infomation about an Opaque definition, particularly useful in `RPITIT`.
1583+ #[ derive( Serialize ) ]
1584+ pub OpaqueDef ;
1585+ }
1586+
1587+ crate_def ! {
1588+ #[ derive( Serialize ) ]
1589+ pub AssocDef ;
1590+ }
1591+
1592+ #[ derive( Clone , Debug , Eq , PartialEq , Serialize ) ]
1593+ pub struct AssocItem {
1594+ pub def_id : AssocDef ,
1595+ pub name : Symbol ,
1596+ pub kind : AssocKind ,
1597+ pub container : AssocItemContainer ,
1598+
1599+ /// If this is an item in an impl of a trait then this is the `DefId` of
1600+ /// the associated item on the trait that this implements.
1601+ pub trait_item_def_id : Option < AssocDef > ,
1602+
1603+ /// Whether this is a method with an explicit self
1604+ /// as its first parameter, allowing method calls.
1605+ pub fn_has_self_parameter : bool ,
1606+
1607+ /// `Some` if the associated item (an associated type) comes from the
1608+ /// return-position `impl Trait` in trait desugaring. The `ImplTraitInTraitData`
1609+ /// provides additional information about its source.
1610+ pub opt_rpitit_info : Option < ImplTraitInTraitData > ,
1611+ }
1612+
1613+ #[ derive( Clone , Debug , Eq , PartialEq , Serialize ) ]
1614+ pub enum AssocKind {
1615+ Const ,
1616+ Fn ,
1617+ Type ,
1618+ }
1619+
1620+ #[ derive( Clone , Debug , Eq , PartialEq , Serialize ) ]
1621+ pub enum AssocItemContainer {
1622+ Trait ,
1623+ Impl ,
1624+ }
1625+
1626+ #[ derive( Clone , Copy , PartialEq , Eq , Debug , Hash , Serialize ) ]
1627+ pub enum ImplTraitInTraitData {
1628+ Trait { fn_def_id : FnDef , opaque_def_id : OpaqueDef } ,
1629+ Impl { fn_def_id : FnDef } ,
1630+ }
1631+
1632+ impl AssocItem {
1633+ pub fn is_impl_trait_in_trait ( & self ) -> bool {
1634+ self . opt_rpitit_info . is_some ( )
1635+ }
1636+ }
0 commit comments