aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-06-23 17:46:08 +0100
committerJonas Schievink <[email protected]>2020-06-24 15:53:56 +0100
commitf9a1a9cd3c7757ca3f8ba59287b5d36645008b9b (patch)
treeaf7502e953fd01422db014cbc5b30685f9369480
parentb5fd02d93cdfafeba23f50ca9c414053aaa548ae (diff)
Merge item tree traits
The Source trait isn't needed anymore since we no longer merge extern crate items with use items.
-rw-r--r--crates/ra_hir_def/src/body/lower.rs4
-rw-r--r--crates/ra_hir_def/src/item_tree.rs27
-rw-r--r--crates/ra_hir_def/src/src.rs6
3 files changed, 16 insertions, 21 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index bbde0b802..a74136b8e 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -27,7 +27,7 @@ use crate::{
27 LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, 27 LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
28 }, 28 },
29 item_scope::BuiltinShadowMode, 29 item_scope::BuiltinShadowMode,
30 item_tree::{FileItemTreeId, ItemTree, ItemTreeSource}, 30 item_tree::{FileItemTreeId, ItemTree, ItemTreeNode},
31 path::{GenericArgs, Path}, 31 path::{GenericArgs, Path},
32 type_ref::{Mutability, Rawness, TypeRef}, 32 type_ref::{Mutability, Rawness, TypeRef},
33 AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, 33 AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId,
@@ -557,7 +557,7 @@ impl ExprCollector<'_> {
557 } 557 }
558 } 558 }
559 559
560 fn find_inner_item<S: ItemTreeSource>(&self, id: AstId<ast::ModuleItem>) -> FileItemTreeId<S> { 560 fn find_inner_item<S: ItemTreeNode>(&self, id: AstId<ast::ModuleItem>) -> FileItemTreeId<S> {
561 let index = 561 let index =
562 self.item_trees.iter().position(|(file, _)| *file == id.file_id).unwrap_or_else(|| { 562 self.item_trees.iter().position(|(file, _)| *file == id.file_id).unwrap_or_else(|| {
563 panic!("couldn't find item tree for file {:?}", id.file_id); 563 panic!("couldn't find item tree for file {:?}", id.file_id);
diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs
index 5beb11df7..a75271703 100644
--- a/crates/ra_hir_def/src/item_tree.rs
+++ b/crates/ra_hir_def/src/item_tree.rs
@@ -153,7 +153,7 @@ impl ItemTree {
153 self.inner_items.values().flatten().copied() 153 self.inner_items.values().flatten().copied()
154 } 154 }
155 155
156 pub fn source<S: ItemTreeSource>( 156 pub fn source<S: ItemTreeNode>(
157 &self, 157 &self,
158 db: &dyn DefDatabase, 158 db: &dyn DefDatabase,
159 of: FileItemTreeId<S>, 159 of: FileItemTreeId<S>,
@@ -173,6 +173,10 @@ impl ItemTree {
173 173
174/// Trait implemented by all nodes in the item tree. 174/// Trait implemented by all nodes in the item tree.
175pub trait ItemTreeNode: Clone { 175pub trait ItemTreeNode: Clone {
176 type Source: AstNode + Into<ast::ModuleItem>;
177
178 fn ast_id(&self) -> FileAstId<Self::Source>;
179
176 /// Looks up an instance of `Self` in an item tree. 180 /// Looks up an instance of `Self` in an item tree.
177 fn lookup(tree: &ItemTree, index: Idx<Self>) -> &Self; 181 fn lookup(tree: &ItemTree, index: Idx<Self>) -> &Self;
178 182
@@ -183,13 +187,6 @@ pub trait ItemTreeNode: Clone {
183 fn id_to_mod_item(id: FileItemTreeId<Self>) -> ModItem; 187 fn id_to_mod_item(id: FileItemTreeId<Self>) -> ModItem;
184} 188}
185 189
186/// Trait for item tree nodes that allow accessing the original AST node.
187pub trait ItemTreeSource: ItemTreeNode {
188 type Source: AstNode + Into<ast::ModuleItem>;
189
190 fn ast_id(&self) -> FileAstId<Self::Source>;
191}
192
193pub struct FileItemTreeId<N: ItemTreeNode> { 190pub struct FileItemTreeId<N: ItemTreeNode> {
194 index: Idx<N>, 191 index: Idx<N>,
195 _p: PhantomData<N>, 192 _p: PhantomData<N>,
@@ -242,6 +239,12 @@ macro_rules! mod_items {
242 239
243 $( 240 $(
244 impl ItemTreeNode for $typ { 241 impl ItemTreeNode for $typ {
242 type Source = $ast;
243
244 fn ast_id(&self) -> FileAstId<Self::Source> {
245 self.ast_id
246 }
247
245 fn lookup(tree: &ItemTree, index: Idx<Self>) -> &Self { 248 fn lookup(tree: &ItemTree, index: Idx<Self>) -> &Self {
246 &tree.$fld[index] 249 &tree.$fld[index]
247 } 250 }
@@ -259,14 +262,6 @@ macro_rules! mod_items {
259 } 262 }
260 } 263 }
261 264
262 impl ItemTreeSource for $typ {
263 type Source = $ast;
264
265 fn ast_id(&self) -> FileAstId<Self::Source> {
266 self.ast_id
267 }
268 }
269
270 impl Index<Idx<$typ>> for ItemTree { 265 impl Index<Idx<$typ>> for ItemTree {
271 type Output = $typ; 266 type Output = $typ;
272 267
diff --git a/crates/ra_hir_def/src/src.rs b/crates/ra_hir_def/src/src.rs
index 10e21d48e..043b93fad 100644
--- a/crates/ra_hir_def/src/src.rs
+++ b/crates/ra_hir_def/src/src.rs
@@ -3,14 +3,14 @@
3use hir_expand::InFile; 3use hir_expand::InFile;
4use ra_arena::map::ArenaMap; 4use ra_arena::map::ArenaMap;
5 5
6use crate::{db::DefDatabase, item_tree::ItemTreeSource, AssocItemLoc, ItemLoc}; 6use crate::{db::DefDatabase, item_tree::ItemTreeNode, AssocItemLoc, ItemLoc};
7 7
8pub trait HasSource { 8pub trait HasSource {
9 type Value; 9 type Value;
10 fn source(&self, db: &dyn DefDatabase) -> InFile<Self::Value>; 10 fn source(&self, db: &dyn DefDatabase) -> InFile<Self::Value>;
11} 11}
12 12
13impl<N: ItemTreeSource> HasSource for AssocItemLoc<N> { 13impl<N: ItemTreeNode> HasSource for AssocItemLoc<N> {
14 type Value = N::Source; 14 type Value = N::Source;
15 15
16 fn source(&self, db: &dyn DefDatabase) -> InFile<N::Source> { 16 fn source(&self, db: &dyn DefDatabase) -> InFile<N::Source> {
@@ -23,7 +23,7 @@ impl<N: ItemTreeSource> HasSource for AssocItemLoc<N> {
23 } 23 }
24} 24}
25 25
26impl<N: ItemTreeSource> HasSource for ItemLoc<N> { 26impl<N: ItemTreeNode> HasSource for ItemLoc<N> {
27 type Value = N::Source; 27 type Value = N::Source;
28 28
29 fn source(&self, db: &dyn DefDatabase) -> InFile<N::Source> { 29 fn source(&self, db: &dyn DefDatabase) -> InFile<N::Source> {