aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/module.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/module.rs')
-rw-r--r--crates/ra_hir/src/module.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/crates/ra_hir/src/module.rs b/crates/ra_hir/src/module.rs
index b9d36f01f..43413acb8 100644
--- a/crates/ra_hir/src/module.rs
+++ b/crates/ra_hir/src/module.rs
@@ -7,13 +7,14 @@ use log;
7use ra_syntax::{ 7use ra_syntax::{
8 algo::generate, 8 algo::generate,
9 ast::{self, AstNode, NameOwner}, 9 ast::{self, AstNode, NameOwner},
10 SmolStr, SyntaxNode, 10 SyntaxNode,
11}; 11};
12use ra_db::{SourceRootId, FileId, Cancelable}; 12use ra_db::{SourceRootId, FileId, Cancelable};
13use relative_path::RelativePathBuf; 13use relative_path::RelativePathBuf;
14 14
15use crate::{ 15use crate::{
16 DefKind, DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate, 16 DefKind, DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate,
17 Name,
17 arena::{Arena, Id}, 18 arena::{Arena, Id},
18}; 19};
19 20
@@ -84,7 +85,7 @@ impl Module {
84 } 85 }
85 86
86 /// `name` is `None` for the crate's root module 87 /// `name` is `None` for the crate's root module
87 pub fn name(&self) -> Option<SmolStr> { 88 pub fn name(&self) -> Option<&Name> {
88 let link = self.module_id.parent_link(&self.tree)?; 89 let link = self.module_id.parent_link(&self.tree)?;
89 Some(link.name(&self.tree)) 90 Some(link.name(&self.tree))
90 } 91 }
@@ -100,7 +101,7 @@ impl Module {
100 } 101 }
101 102
102 /// Finds a child module with the specified name. 103 /// Finds a child module with the specified name.
103 pub fn child(&self, name: &str) -> Option<Module> { 104 pub fn child(&self, name: &Name) -> Option<Module> {
104 let child_id = self.module_id.child(&self.tree, name)?; 105 let child_id = self.module_id.child(&self.tree, name)?;
105 Some(Module { 106 Some(Module {
106 module_id: child_id, 107 module_id: child_id,
@@ -230,15 +231,15 @@ impl ModuleId {
230 .last() 231 .last()
231 .unwrap() 232 .unwrap()
232 } 233 }
233 fn child(self, tree: &ModuleTree, name: &str) -> Option<ModuleId> { 234 fn child(self, tree: &ModuleTree, name: &Name) -> Option<ModuleId> {
234 let link = tree.mods[self] 235 let link = tree.mods[self]
235 .children 236 .children
236 .iter() 237 .iter()
237 .map(|&it| &tree.links[it]) 238 .map(|&it| &tree.links[it])
238 .find(|it| it.name == name)?; 239 .find(|it| it.name == *name)?;
239 Some(*link.points_to.first()?) 240 Some(*link.points_to.first()?)
240 } 241 }
241 fn children<'a>(self, tree: &'a ModuleTree) -> impl Iterator<Item = (SmolStr, ModuleId)> + 'a { 242 fn children<'a>(self, tree: &'a ModuleTree) -> impl Iterator<Item = (Name, ModuleId)> + 'a {
242 tree.mods[self].children.iter().filter_map(move |&it| { 243 tree.mods[self].children.iter().filter_map(move |&it| {
243 let link = &tree.links[it]; 244 let link = &tree.links[it];
244 let module = *link.points_to.first()?; 245 let module = *link.points_to.first()?;
@@ -263,8 +264,8 @@ impl LinkId {
263 fn owner(self, tree: &ModuleTree) -> ModuleId { 264 fn owner(self, tree: &ModuleTree) -> ModuleId {
264 tree.links[self].owner 265 tree.links[self].owner
265 } 266 }
266 fn name(self, tree: &ModuleTree) -> SmolStr { 267 fn name(self, tree: &ModuleTree) -> &Name {
267 tree.links[self].name.clone() 268 &tree.links[self].name
268 } 269 }
269 fn bind_source<'a>(self, tree: &ModuleTree, db: &impl HirDatabase) -> ast::ModuleNode { 270 fn bind_source<'a>(self, tree: &ModuleTree, db: &impl HirDatabase) -> ast::ModuleNode {
270 let owner = self.owner(tree); 271 let owner = self.owner(tree);
@@ -328,7 +329,7 @@ impl ModuleSource {
328#[derive(Hash, Debug, PartialEq, Eq)] 329#[derive(Hash, Debug, PartialEq, Eq)]
329struct LinkData { 330struct LinkData {
330 owner: ModuleId, 331 owner: ModuleId,
331 name: SmolStr, 332 name: Name,
332 points_to: Vec<ModuleId>, 333 points_to: Vec<ModuleId>,
333 problem: Option<Problem>, 334 problem: Option<Problem>,
334} 335}