From d963042ca9da93be8d5922ce46ea26dc6a79c929 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 27 Dec 2018 20:07:21 +0300 Subject: introduce hir::Name --- crates/ra_hir/src/module/nameres.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'crates/ra_hir/src/module/nameres.rs') diff --git a/crates/ra_hir/src/module/nameres.rs b/crates/ra_hir/src/module/nameres.rs index 98cd225dd..68eb02a98 100644 --- a/crates/ra_hir/src/module/nameres.rs +++ b/crates/ra_hir/src/module/nameres.rs @@ -14,14 +14,12 @@ //! modifications (that is, typing inside a function shold not change IMIs), //! such that the results of name resolution can be preserved unless the module //! structure itself is modified. -use std::{ - sync::Arc, -}; +use std::sync::Arc; use rustc_hash::FxHashMap; use ra_syntax::{ TextRange, - SmolStr, SyntaxKind::{self, *}, + SyntaxKind::{self, *}, ast::{self, AstNode} }; use ra_db::SourceRootId; @@ -32,6 +30,7 @@ use crate::{ SourceItemId, SourceFileItemId, SourceFileItems, Path, PathKind, HirDatabase, Crate, + Name, AsName, module::{Module, ModuleId, ModuleTree}, }; @@ -45,14 +44,14 @@ pub struct ItemMap { #[derive(Debug, Default, PartialEq, Eq, Clone)] pub struct ModuleScope { - items: FxHashMap, + items: FxHashMap, } impl ModuleScope { - pub fn entries<'a>(&'a self) -> impl Iterator + 'a { + pub fn entries<'a>(&'a self) -> impl Iterator + 'a { self.items.iter() } - pub fn get(&self, name: &SmolStr) -> Option<&Resolution> { + pub fn get(&self, name: &Name) -> Option<&Resolution> { self.items.get(name) } } @@ -72,7 +71,7 @@ pub struct InputModuleItems { #[derive(Debug, PartialEq, Eq)] struct ModuleItem { id: SourceFileItemId, - name: SmolStr, + name: Name, kind: SyntaxKind, vis: Vis, } @@ -260,7 +259,7 @@ impl InputModuleItems { impl ModuleItem { fn new<'a>(file_items: &SourceFileItems, item: impl ast::NameOwner<'a>) -> Option { - let name = item.name()?.text(); + let name = item.name()?.as_name(); let kind = item.syntax().kind(); let vis = Vis::Other; let id = file_items.id_of_unchecked(item.syntax()); @@ -328,7 +327,11 @@ where for dep in krate.dependencies(self.db) { if let Some(module) = dep.krate.root_module(self.db)? { let def_id = module.def_id(self.db); - self.add_module_item(&mut module_items, dep.name, PerNs::types(def_id)); + self.add_module_item( + &mut module_items, + dep.name.clone(), + PerNs::types(def_id), + ); } } }; @@ -389,7 +392,7 @@ where Ok(()) } - fn add_module_item(&self, module_items: &mut ModuleScope, name: SmolStr, def_id: PerNs) { + fn add_module_item(&self, module_items: &mut ModuleScope, name: Name, def_id: PerNs) { let resolution = Resolution { def_id, import: None, -- cgit v1.2.3