diff options
Diffstat (limited to 'crates/ra_hir_def/src/item_tree')
-rw-r--r-- | crates/ra_hir_def/src/item_tree/lower.rs | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index d123a7310..0c9454848 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs | |||
@@ -5,6 +5,10 @@ use ra_syntax::ast::{self, ModuleItemOwner}; | |||
5 | use smallvec::SmallVec; | 5 | use smallvec::SmallVec; |
6 | use std::sync::Arc; | 6 | use std::sync::Arc; |
7 | 7 | ||
8 | fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> { | ||
9 | FileItemTreeId { index, _p: PhantomData } | ||
10 | } | ||
11 | |||
8 | struct ModItems(SmallVec<[ModItem; 1]>); | 12 | struct ModItems(SmallVec<[ModItem; 1]>); |
9 | 13 | ||
10 | impl<T> From<T> for ModItems | 14 | impl<T> From<T> for ModItems |
@@ -38,54 +42,54 @@ impl Ctx { | |||
38 | let attrs = Attrs::new(item, &self.hygiene); | 42 | let attrs = Attrs::new(item, &self.hygiene); |
39 | let items = match item { | 43 | let items = match item { |
40 | ast::ModuleItem::StructDef(ast) => { | 44 | ast::ModuleItem::StructDef(ast) => { |
41 | self.lower_struct(ast).map(|data| self.tree.structs.alloc(data).into()) | 45 | self.lower_struct(ast).map(|data| id(self.tree.structs.alloc(data)).into()) |
42 | } | 46 | } |
43 | ast::ModuleItem::UnionDef(ast) => { | 47 | ast::ModuleItem::UnionDef(ast) => { |
44 | self.lower_union(ast).map(|data| self.tree.unions.alloc(data).into()) | 48 | self.lower_union(ast).map(|data| id(self.tree.unions.alloc(data)).into()) |
45 | } | 49 | } |
46 | ast::ModuleItem::EnumDef(ast) => { | 50 | ast::ModuleItem::EnumDef(ast) => { |
47 | self.lower_enum(ast).map(|data| self.tree.enums.alloc(data).into()) | 51 | self.lower_enum(ast).map(|data| id(self.tree.enums.alloc(data)).into()) |
48 | } | 52 | } |
49 | ast::ModuleItem::FnDef(ast) => { | 53 | ast::ModuleItem::FnDef(ast) => { |
50 | self.lower_function(ast).map(|data| self.tree.functions.alloc(data).into()) | 54 | self.lower_function(ast).map(|data| id(self.tree.functions.alloc(data)).into()) |
51 | } | 55 | } |
52 | ast::ModuleItem::TypeAliasDef(ast) => { | 56 | ast::ModuleItem::TypeAliasDef(ast) => { |
53 | self.lower_type_alias(ast).map(|data| self.tree.type_aliases.alloc(data).into()) | 57 | self.lower_type_alias(ast).map(|data| id(self.tree.type_aliases.alloc(data)).into()) |
54 | } | 58 | } |
55 | ast::ModuleItem::StaticDef(ast) => { | 59 | ast::ModuleItem::StaticDef(ast) => { |
56 | self.lower_static(ast).map(|data| self.tree.statics.alloc(data).into()) | 60 | self.lower_static(ast).map(|data| id(self.tree.statics.alloc(data)).into()) |
57 | } | 61 | } |
58 | ast::ModuleItem::ConstDef(ast) => { | 62 | ast::ModuleItem::ConstDef(ast) => { |
59 | let data = self.lower_const(ast); | 63 | let data = self.lower_const(ast); |
60 | Some(self.tree.consts.alloc(data).into()) | 64 | Some(id(self.tree.consts.alloc(data)).into()) |
61 | } | 65 | } |
62 | ast::ModuleItem::Module(ast) => { | 66 | ast::ModuleItem::Module(ast) => { |
63 | self.lower_module(ast).map(|data| self.tree.mods.alloc(data).into()) | 67 | self.lower_module(ast).map(|data| id(self.tree.mods.alloc(data)).into()) |
64 | } | 68 | } |
65 | ast::ModuleItem::TraitDef(ast) => { | 69 | ast::ModuleItem::TraitDef(ast) => { |
66 | self.lower_trait(ast).map(|data| self.tree.traits.alloc(data).into()) | 70 | self.lower_trait(ast).map(|data| id(self.tree.traits.alloc(data)).into()) |
67 | } | 71 | } |
68 | ast::ModuleItem::ImplDef(ast) => { | 72 | ast::ModuleItem::ImplDef(ast) => { |
69 | self.lower_impl(ast).map(|data| self.tree.impls.alloc(data).into()) | 73 | self.lower_impl(ast).map(|data| id(self.tree.impls.alloc(data)).into()) |
70 | } | 74 | } |
71 | ast::ModuleItem::UseItem(ast) => Some(ModItems( | 75 | ast::ModuleItem::UseItem(ast) => Some(ModItems( |
72 | self.lower_use(ast) | 76 | self.lower_use(ast) |
73 | .into_iter() | 77 | .into_iter() |
74 | .map(|data| self.tree.imports.alloc(data).into()) | 78 | .map(|data| id(self.tree.imports.alloc(data)).into()) |
75 | .collect::<SmallVec<_>>(), | 79 | .collect::<SmallVec<_>>(), |
76 | )), | 80 | )), |
77 | ast::ModuleItem::ExternCrateItem(ast) => { | 81 | ast::ModuleItem::ExternCrateItem(ast) => { |
78 | self.lower_extern_crate(ast).map(|data| self.tree.imports.alloc(data).into()) | 82 | self.lower_extern_crate(ast).map(|data| id(self.tree.imports.alloc(data)).into()) |
79 | } | 83 | } |
80 | ast::ModuleItem::MacroCall(ast) => { | 84 | ast::ModuleItem::MacroCall(ast) => { |
81 | self.lower_macro_call(ast).map(|data| self.tree.macro_calls.alloc(data).into()) | 85 | self.lower_macro_call(ast).map(|data| id(self.tree.macro_calls.alloc(data)).into()) |
82 | } | 86 | } |
83 | ast::ModuleItem::ExternBlock(ast) => Some(ModItems( | 87 | ast::ModuleItem::ExternBlock(ast) => Some(ModItems( |
84 | self.lower_extern_block(ast) | 88 | self.lower_extern_block(ast) |
85 | .into_iter() | 89 | .into_iter() |
86 | .map(|item| match item { | 90 | .map(|item| match item { |
87 | Either::Left(func) => self.tree.functions.alloc(func).into(), | 91 | Either::Left(func) => id(self.tree.functions.alloc(func)).into(), |
88 | Either::Right(statik) => self.tree.statics.alloc(statik).into(), | 92 | Either::Right(statik) => id(self.tree.statics.alloc(statik)).into(), |
89 | }) | 93 | }) |
90 | .collect::<SmallVec<_>>(), | 94 | .collect::<SmallVec<_>>(), |
91 | )), | 95 | )), |
@@ -103,14 +107,14 @@ impl Ctx { | |||
103 | fn lower_assoc_item(&mut self, item: &ast::AssocItem) -> Option<AssocItem> { | 107 | fn lower_assoc_item(&mut self, item: &ast::AssocItem) -> Option<AssocItem> { |
104 | match item { | 108 | match item { |
105 | ast::AssocItem::FnDef(ast) => { | 109 | ast::AssocItem::FnDef(ast) => { |
106 | self.lower_function(ast).map(|data| self.tree.functions.alloc(data).into()) | 110 | self.lower_function(ast).map(|data| id(self.tree.functions.alloc(data)).into()) |
107 | } | 111 | } |
108 | ast::AssocItem::TypeAliasDef(ast) => { | 112 | ast::AssocItem::TypeAliasDef(ast) => { |
109 | self.lower_type_alias(ast).map(|data| self.tree.type_aliases.alloc(data).into()) | 113 | self.lower_type_alias(ast).map(|data| id(self.tree.type_aliases.alloc(data)).into()) |
110 | } | 114 | } |
111 | ast::AssocItem::ConstDef(ast) => { | 115 | ast::AssocItem::ConstDef(ast) => { |
112 | let data = self.lower_const(ast); | 116 | let data = self.lower_const(ast); |
113 | Some(self.tree.consts.alloc(data).into()) | 117 | Some(id(self.tree.consts.alloc(data)).into()) |
114 | } | 118 | } |
115 | } | 119 | } |
116 | } | 120 | } |