From f9a1a9cd3c7757ca3f8ba59287b5d36645008b9b Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 23 Jun 2020 18:46:08 +0200 Subject: Merge item tree traits The Source trait isn't needed anymore since we no longer merge extern crate items with use items. --- crates/ra_hir_def/src/body/lower.rs | 4 ++-- crates/ra_hir_def/src/item_tree.rs | 27 +++++++++++---------------- crates/ra_hir_def/src/src.rs | 6 +++--- 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::{ LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, }, item_scope::BuiltinShadowMode, - item_tree::{FileItemTreeId, ItemTree, ItemTreeSource}, + item_tree::{FileItemTreeId, ItemTree, ItemTreeNode}, path::{GenericArgs, Path}, type_ref::{Mutability, Rawness, TypeRef}, AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, @@ -557,7 +557,7 @@ impl ExprCollector<'_> { } } - fn find_inner_item(&self, id: AstId) -> FileItemTreeId { + fn find_inner_item(&self, id: AstId) -> FileItemTreeId { let index = self.item_trees.iter().position(|(file, _)| *file == id.file_id).unwrap_or_else(|| { 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 { self.inner_items.values().flatten().copied() } - pub fn source( + pub fn source( &self, db: &dyn DefDatabase, of: FileItemTreeId, @@ -173,6 +173,10 @@ impl ItemTree { /// Trait implemented by all nodes in the item tree. pub trait ItemTreeNode: Clone { + type Source: AstNode + Into; + + fn ast_id(&self) -> FileAstId; + /// Looks up an instance of `Self` in an item tree. fn lookup(tree: &ItemTree, index: Idx) -> &Self; @@ -183,13 +187,6 @@ pub trait ItemTreeNode: Clone { fn id_to_mod_item(id: FileItemTreeId) -> ModItem; } -/// Trait for item tree nodes that allow accessing the original AST node. -pub trait ItemTreeSource: ItemTreeNode { - type Source: AstNode + Into; - - fn ast_id(&self) -> FileAstId; -} - pub struct FileItemTreeId { index: Idx, _p: PhantomData, @@ -242,6 +239,12 @@ macro_rules! mod_items { $( impl ItemTreeNode for $typ { + type Source = $ast; + + fn ast_id(&self) -> FileAstId { + self.ast_id + } + fn lookup(tree: &ItemTree, index: Idx) -> &Self { &tree.$fld[index] } @@ -259,14 +262,6 @@ macro_rules! mod_items { } } - impl ItemTreeSource for $typ { - type Source = $ast; - - fn ast_id(&self) -> FileAstId { - self.ast_id - } - } - impl Index> for ItemTree { type Output = $typ; 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 @@ use hir_expand::InFile; use ra_arena::map::ArenaMap; -use crate::{db::DefDatabase, item_tree::ItemTreeSource, AssocItemLoc, ItemLoc}; +use crate::{db::DefDatabase, item_tree::ItemTreeNode, AssocItemLoc, ItemLoc}; pub trait HasSource { type Value; fn source(&self, db: &dyn DefDatabase) -> InFile; } -impl HasSource for AssocItemLoc { +impl HasSource for AssocItemLoc { type Value = N::Source; fn source(&self, db: &dyn DefDatabase) -> InFile { @@ -23,7 +23,7 @@ impl HasSource for AssocItemLoc { } } -impl HasSource for ItemLoc { +impl HasSource for ItemLoc { type Value = N::Source; fn source(&self, db: &dyn DefDatabase) -> InFile { -- cgit v1.2.3