29
29
//!
30
30
//! In general, any item in the `ItemTree` stores its `AstId`, which allows mapping it back to its
31
31
//! surface syntax.
32
- #![ allow( unexpected_cfgs) ]
33
32
34
33
mod lower;
35
34
mod pretty;
@@ -51,7 +50,7 @@ use hir_expand::{
51
50
mod_path:: { ModPath , PathKind } ,
52
51
name:: Name ,
53
52
} ;
54
- use intern:: { Interned , Symbol } ;
53
+ use intern:: Interned ;
55
54
use la_arena:: { Arena , Idx , RawIdx } ;
56
55
use rustc_hash:: FxHashMap ;
57
56
use smallvec:: SmallVec ;
@@ -237,7 +236,6 @@ impl ItemTree {
237
236
structs,
238
237
unions,
239
238
enums,
240
- variants,
241
239
consts,
242
240
statics,
243
241
traits,
@@ -258,7 +256,6 @@ impl ItemTree {
258
256
structs. shrink_to_fit ( ) ;
259
257
unions. shrink_to_fit ( ) ;
260
258
enums. shrink_to_fit ( ) ;
261
- variants. shrink_to_fit ( ) ;
262
259
consts. shrink_to_fit ( ) ;
263
260
statics. shrink_to_fit ( ) ;
264
261
traits. shrink_to_fit ( ) ;
@@ -310,7 +307,6 @@ struct ItemTreeData {
310
307
structs : Arena < Struct > ,
311
308
unions : Arena < Union > ,
312
309
enums : Arena < Enum > ,
313
- variants : Arena < Variant > ,
314
310
consts : Arena < Const > ,
315
311
statics : Arena < Static > ,
316
312
traits : Arena < Trait > ,
@@ -340,41 +336,15 @@ pub enum AttrOwner {
340
336
ModItem ( ModItem ) ,
341
337
/// Inner attributes of the source file.
342
338
TopLevel ,
343
-
344
- Variant ( FileItemTreeId < Variant > ) ,
345
- // while not relevant to early name resolution, fields can contain visibility
346
- Field ( FieldParent , ItemTreeFieldId ) ,
347
339
}
348
340
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)
352
345
}
353
346
}
354
347
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
-
378
348
/// Trait implemented by all nodes in the item tree.
379
349
pub trait ItemTreeNode : Clone {
380
350
type Source : AstIdNode ;
@@ -383,7 +353,6 @@ pub trait ItemTreeNode: Clone {
383
353
384
354
/// Looks up an instance of `Self` in an item tree.
385
355
fn lookup ( tree : & ItemTree , index : Idx < Self > ) -> & Self ;
386
- fn attr_owner ( id : FileItemTreeId < Self > ) -> AttrOwner ;
387
356
}
388
357
389
358
pub struct FileItemTreeId < N > ( Idx < N > ) ;
@@ -547,10 +516,6 @@ macro_rules! mod_items {
547
516
fn lookup( tree: & ItemTree , index: Idx <Self >) -> & Self {
548
517
& tree. data( ) . $fld[ index]
549
518
}
550
-
551
- fn attr_owner( id: FileItemTreeId <Self >) -> AttrOwner {
552
- AttrOwner :: ModItem ( ModItem :: $typ( id) )
553
- }
554
519
}
555
520
556
521
impl Index <Idx <$typ>> for ItemTree {
@@ -624,22 +589,6 @@ impl<N: ItemTreeNode> Index<FileItemTreeId<N>> for ItemTree {
624
589
}
625
590
}
626
591
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
-
643
592
#[ derive( Debug , Clone , Eq , PartialEq ) ]
644
593
pub struct Use {
645
594
pub visibility : RawVisibilityId ,
@@ -712,7 +661,6 @@ pub struct ExternCrate {
712
661
713
662
#[ derive( Debug , Clone , Eq , PartialEq ) ]
714
663
pub struct ExternBlock {
715
- pub abi : Option < Symbol > ,
716
664
pub ast_id : FileAstId < ast:: ExternBlock > ,
717
665
pub children : Box < [ ModItem ] > ,
718
666
}
@@ -728,7 +676,6 @@ pub struct Function {
728
676
pub struct Struct {
729
677
pub name : Name ,
730
678
pub visibility : RawVisibilityId ,
731
- pub fields : Box < [ Field ] > ,
732
679
pub shape : FieldsShape ,
733
680
pub ast_id : FileAstId < ast:: Struct > ,
734
681
}
@@ -737,26 +684,16 @@ pub struct Struct {
737
684
pub struct Union {
738
685
pub name : Name ,
739
686
pub visibility : RawVisibilityId ,
740
- pub fields : Box < [ Field ] > ,
741
687
pub ast_id : FileAstId < ast:: Union > ,
742
688
}
743
689
744
690
#[ derive( Debug , Clone , Eq , PartialEq ) ]
745
691
pub struct Enum {
746
692
pub name : Name ,
747
693
pub visibility : RawVisibilityId ,
748
- pub variants : Range < FileItemTreeId < Variant > > ,
749
694
pub ast_id : FileAstId < ast:: Enum > ,
750
695
}
751
696
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
-
760
697
#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
761
698
pub enum FieldsShape {
762
699
Record ,
@@ -788,16 +725,6 @@ impl VisibilityExplicitness {
788
725
}
789
726
}
790
727
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
-
801
728
#[ derive( Debug , Clone , Eq , PartialEq ) ]
802
729
pub struct Const {
803
730
/// `None` for `const _: () = ();`
@@ -817,7 +744,6 @@ pub struct Static {
817
744
pub struct Trait {
818
745
pub name : Name ,
819
746
pub visibility : RawVisibilityId ,
820
- pub items : Box < [ AssocItem ] > ,
821
747
pub ast_id : FileAstId < ast:: Trait > ,
822
748
}
823
749
@@ -830,7 +756,6 @@ pub struct TraitAlias {
830
756
831
757
#[ derive( Debug , Clone , Eq , PartialEq ) ]
832
758
pub struct Impl {
833
- pub items : Box < [ AssocItem ] > ,
834
759
pub ast_id : FileAstId < ast:: Impl > ,
835
760
}
836
761
@@ -971,76 +896,3 @@ impl UseTree {
971
896
}
972
897
}
973
898
}
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