2929//!
3030//! In general, any item in the `ItemTree` stores its `AstId`, which allows mapping it back to its
3131//! surface syntax.
32- #![ allow( unexpected_cfgs) ]
3332
3433mod lower;
3534mod pretty;
@@ -51,7 +50,7 @@ use hir_expand::{
5150 mod_path:: { ModPath , PathKind } ,
5251 name:: Name ,
5352} ;
54- use intern:: { Interned , Symbol } ;
53+ use intern:: Interned ;
5554use la_arena:: { Arena , Idx , RawIdx } ;
5655use rustc_hash:: FxHashMap ;
5756use smallvec:: SmallVec ;
@@ -237,7 +236,6 @@ impl ItemTree {
237236 structs,
238237 unions,
239238 enums,
240- variants,
241239 consts,
242240 statics,
243241 traits,
@@ -258,7 +256,6 @@ impl ItemTree {
258256 structs. shrink_to_fit ( ) ;
259257 unions. shrink_to_fit ( ) ;
260258 enums. shrink_to_fit ( ) ;
261- variants. shrink_to_fit ( ) ;
262259 consts. shrink_to_fit ( ) ;
263260 statics. shrink_to_fit ( ) ;
264261 traits. shrink_to_fit ( ) ;
@@ -310,7 +307,6 @@ struct ItemTreeData {
310307 structs : Arena < Struct > ,
311308 unions : Arena < Union > ,
312309 enums : Arena < Enum > ,
313- variants : Arena < Variant > ,
314310 consts : Arena < Const > ,
315311 statics : Arena < Static > ,
316312 traits : Arena < Trait > ,
@@ -340,41 +336,15 @@ pub enum AttrOwner {
340336 ModItem ( ModItem ) ,
341337 /// Inner attributes of the source file.
342338 TopLevel ,
343-
344- Variant ( FileItemTreeId < Variant > ) ,
345- // while not relevant to early name resolution, fields can contain visibility
346- Field ( FieldParent , ItemTreeFieldId ) ,
347339}
348340
349- impl AttrOwner {
350- pub fn make_field_indexed ( parent : FieldParent , idx : usize ) -> Self {
351- AttrOwner :: Field ( parent, ItemTreeFieldId :: from_raw ( RawIdx :: from_u32 ( idx as u32 ) ) )
341+ impl From < ModItem > for AttrOwner {
342+ #[ inline]
343+ fn from ( value : ModItem ) -> Self {
344+ AttrOwner :: ModItem ( value)
352345 }
353346}
354347
355- #[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash ) ]
356- pub enum FieldParent {
357- Struct ( FileItemTreeId < Struct > ) ,
358- Union ( FileItemTreeId < Union > ) ,
359- EnumVariant ( FileItemTreeId < Variant > ) ,
360- }
361-
362- pub type ItemTreeFieldId = Idx < Field > ;
363-
364- macro_rules! from_attrs {
365- ( $( $var: ident( $t: ty) ) ,+ $( , ) ? ) => {
366- $(
367- impl From <$t> for AttrOwner {
368- fn from( t: $t) -> AttrOwner {
369- AttrOwner :: $var( t)
370- }
371- }
372- ) +
373- } ;
374- }
375-
376- from_attrs ! ( ModItem ( ModItem ) , Variant ( FileItemTreeId <Variant >) ) ;
377-
378348/// Trait implemented by all nodes in the item tree.
379349pub trait ItemTreeNode : Clone {
380350 type Source : AstIdNode ;
@@ -383,7 +353,6 @@ pub trait ItemTreeNode: Clone {
383353
384354 /// Looks up an instance of `Self` in an item tree.
385355 fn lookup ( tree : & ItemTree , index : Idx < Self > ) -> & Self ;
386- fn attr_owner ( id : FileItemTreeId < Self > ) -> AttrOwner ;
387356}
388357
389358pub struct FileItemTreeId < N > ( Idx < N > ) ;
@@ -547,10 +516,6 @@ macro_rules! mod_items {
547516 fn lookup( tree: & ItemTree , index: Idx <Self >) -> & Self {
548517 & tree. data( ) . $fld[ index]
549518 }
550-
551- fn attr_owner( id: FileItemTreeId <Self >) -> AttrOwner {
552- AttrOwner :: ModItem ( ModItem :: $typ( id) )
553- }
554519 }
555520
556521 impl Index <Idx <$typ>> for ItemTree {
@@ -624,22 +589,6 @@ impl<N: ItemTreeNode> Index<FileItemTreeId<N>> for ItemTree {
624589 }
625590}
626591
627- impl ItemTreeNode for Variant {
628- type Source = ast:: Variant ;
629-
630- fn ast_id ( & self ) -> FileAstId < Self :: Source > {
631- self . ast_id
632- }
633-
634- fn lookup ( tree : & ItemTree , index : Idx < Self > ) -> & Self {
635- & tree. data ( ) . variants [ index]
636- }
637-
638- fn attr_owner ( id : FileItemTreeId < Self > ) -> AttrOwner {
639- AttrOwner :: Variant ( id)
640- }
641- }
642-
643592#[ derive( Debug , Clone , Eq , PartialEq ) ]
644593pub struct Use {
645594 pub visibility : RawVisibilityId ,
@@ -712,7 +661,6 @@ pub struct ExternCrate {
712661
713662#[ derive( Debug , Clone , Eq , PartialEq ) ]
714663pub struct ExternBlock {
715- pub abi : Option < Symbol > ,
716664 pub ast_id : FileAstId < ast:: ExternBlock > ,
717665 pub children : Box < [ ModItem ] > ,
718666}
@@ -728,7 +676,6 @@ pub struct Function {
728676pub struct Struct {
729677 pub name : Name ,
730678 pub visibility : RawVisibilityId ,
731- pub fields : Box < [ Field ] > ,
732679 pub shape : FieldsShape ,
733680 pub ast_id : FileAstId < ast:: Struct > ,
734681}
@@ -737,26 +684,16 @@ pub struct Struct {
737684pub struct Union {
738685 pub name : Name ,
739686 pub visibility : RawVisibilityId ,
740- pub fields : Box < [ Field ] > ,
741687 pub ast_id : FileAstId < ast:: Union > ,
742688}
743689
744690#[ derive( Debug , Clone , Eq , PartialEq ) ]
745691pub struct Enum {
746692 pub name : Name ,
747693 pub visibility : RawVisibilityId ,
748- pub variants : Range < FileItemTreeId < Variant > > ,
749694 pub ast_id : FileAstId < ast:: Enum > ,
750695}
751696
752- #[ derive( Debug , Clone , PartialEq , Eq ) ]
753- pub struct Variant {
754- pub name : Name ,
755- pub fields : Box < [ Field ] > ,
756- pub shape : FieldsShape ,
757- pub ast_id : FileAstId < ast:: Variant > ,
758- }
759-
760697#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
761698pub enum FieldsShape {
762699 Record ,
@@ -788,16 +725,6 @@ impl VisibilityExplicitness {
788725 }
789726}
790727
791- // FIXME: Remove this from item tree?
792- /// A single field of an enum variant or struct
793- #[ derive( Debug , Clone , PartialEq , Eq ) ]
794- pub struct Field {
795- pub name : Name ,
796- pub visibility : RawVisibilityId ,
797- // FIXME: Not an item tree property
798- pub is_unsafe : bool ,
799- }
800-
801728#[ derive( Debug , Clone , Eq , PartialEq ) ]
802729pub struct Const {
803730 /// `None` for `const _: () = ();`
@@ -817,7 +744,6 @@ pub struct Static {
817744pub struct Trait {
818745 pub name : Name ,
819746 pub visibility : RawVisibilityId ,
820- pub items : Box < [ AssocItem ] > ,
821747 pub ast_id : FileAstId < ast:: Trait > ,
822748}
823749
@@ -830,7 +756,6 @@ pub struct TraitAlias {
830756
831757#[ derive( Debug , Clone , Eq , PartialEq ) ]
832758pub struct Impl {
833- pub items : Box < [ AssocItem ] > ,
834759 pub ast_id : FileAstId < ast:: Impl > ,
835760}
836761
@@ -971,76 +896,3 @@ impl UseTree {
971896 }
972897 }
973898}
974-
975- macro_rules! impl_froms {
976- ( $e: ident { $( $v: ident ( $t: ty) ) ,* $( , ) ? } ) => {
977- $(
978- impl From <$t> for $e {
979- fn from( it: $t) -> $e {
980- $e:: $v( it)
981- }
982- }
983- ) *
984- }
985- }
986-
987- impl ModItem {
988- pub fn as_assoc_item ( & self ) -> Option < AssocItem > {
989- match self {
990- ModItem :: Use ( _)
991- | ModItem :: ExternCrate ( _)
992- | ModItem :: ExternBlock ( _)
993- | ModItem :: Struct ( _)
994- | ModItem :: Union ( _)
995- | ModItem :: Enum ( _)
996- | ModItem :: Static ( _)
997- | ModItem :: Trait ( _)
998- | ModItem :: TraitAlias ( _)
999- | ModItem :: Impl ( _)
1000- | ModItem :: Mod ( _)
1001- | ModItem :: MacroRules ( _)
1002- | ModItem :: Macro2 ( _) => None ,
1003- & ModItem :: MacroCall ( call) => Some ( AssocItem :: MacroCall ( call) ) ,
1004- & ModItem :: Const ( konst) => Some ( AssocItem :: Const ( konst) ) ,
1005- & ModItem :: TypeAlias ( alias) => Some ( AssocItem :: TypeAlias ( alias) ) ,
1006- & ModItem :: Function ( func) => Some ( AssocItem :: Function ( func) ) ,
1007- }
1008- }
1009- }
1010-
1011- #[ derive( Debug , Copy , Clone , Eq , PartialEq ) ]
1012- pub enum AssocItem {
1013- Function ( FileItemTreeId < Function > ) ,
1014- TypeAlias ( FileItemTreeId < TypeAlias > ) ,
1015- Const ( FileItemTreeId < Const > ) ,
1016- MacroCall ( FileItemTreeId < MacroCall > ) ,
1017- }
1018-
1019- impl_froms ! ( AssocItem {
1020- Function ( FileItemTreeId <Function >) ,
1021- TypeAlias ( FileItemTreeId <TypeAlias >) ,
1022- Const ( FileItemTreeId <Const >) ,
1023- MacroCall ( FileItemTreeId <MacroCall >) ,
1024- } ) ;
1025-
1026- impl From < AssocItem > for ModItem {
1027- fn from ( item : AssocItem ) -> Self {
1028- match item {
1029- AssocItem :: Function ( it) => it. into ( ) ,
1030- AssocItem :: TypeAlias ( it) => it. into ( ) ,
1031- AssocItem :: Const ( it) => it. into ( ) ,
1032- AssocItem :: MacroCall ( it) => it. into ( ) ,
1033- }
1034- }
1035- }
1036-
1037- impl AssocItem {
1038- pub fn ast_id ( self , tree : & ItemTree ) -> FileAstId < ast:: AssocItem > {
1039- match self {
1040- AssocItem :: Function ( id) => tree[ id] . ast_id . upcast ( ) ,
1041- AssocItem :: TypeAlias ( id) => tree[ id] . ast_id . upcast ( ) ,
1042- AssocItem :: Const ( id) => tree[ id] . ast_id . upcast ( ) ,
1043- AssocItem :: MacroCall ( id) => tree[ id] . ast_id . upcast ( ) ,
1044- }
1045- }
1046- }
0 commit comments