aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/raw.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-10-10 15:42:29 +0100
committerAleksey Kladov <[email protected]>2019-10-10 15:42:29 +0100
commit89826a50fc59f271b8b52ae675e145029727aa35 (patch)
treeedbce072fccea11cc7331f5b5dbdca40f6a4bbb4 /crates/ra_hir/src/nameres/raw.rs
parentb36b8970ccefa7c98f827caebf6dda71ff3d99c4 (diff)
don't special case path attr
Diffstat (limited to 'crates/ra_hir/src/nameres/raw.rs')
-rw-r--r--crates/ra_hir/src/nameres/raw.rs21
1 files changed, 1 insertions, 20 deletions
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs
index 5f93f920f..469fd8ea7 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir/src/nameres/raw.rs
@@ -5,7 +5,7 @@ use std::{ops::Index, sync::Arc};
5use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; 5use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
6use ra_syntax::{ 6use ra_syntax::{
7 ast::{self, AttrsOwner, NameOwner}, 7 ast::{self, AttrsOwner, NameOwner},
8 AstNode, AstPtr, SmolStr, SourceFile, 8 AstNode, AstPtr, SourceFile,
9}; 9};
10use test_utils::tested_by; 10use test_utils::tested_by;
11 11
@@ -152,14 +152,12 @@ pub(super) enum ModuleData {
152 Declaration { 152 Declaration {
153 name: Name, 153 name: Name,
154 ast_id: FileAstId<ast::Module>, 154 ast_id: FileAstId<ast::Module>,
155 attr_path: Option<SmolStr>,
156 is_macro_use: bool, 155 is_macro_use: bool,
157 }, 156 },
158 Definition { 157 Definition {
159 name: Name, 158 name: Name,
160 ast_id: FileAstId<ast::Module>, 159 ast_id: FileAstId<ast::Module>,
161 items: Vec<RawItem>, 160 items: Vec<RawItem>,
162 attr_path: Option<SmolStr>,
163 is_macro_use: bool, 161 is_macro_use: bool,
164 }, 162 },
165} 163}
@@ -295,11 +293,9 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> {
295 // FIXME: cfg_attr 293 // FIXME: cfg_attr
296 let is_macro_use = module.has_atom_attr("macro_use"); 294 let is_macro_use = module.has_atom_attr("macro_use");
297 if module.has_semi() { 295 if module.has_semi() {
298 let attr_path = extract_mod_path_attribute(&module);
299 let item = self.raw_items.modules.alloc(ModuleData::Declaration { 296 let item = self.raw_items.modules.alloc(ModuleData::Declaration {
300 name, 297 name,
301 ast_id, 298 ast_id,
302 attr_path,
303 is_macro_use, 299 is_macro_use,
304 }); 300 });
305 self.push_item(current_module, attrs, RawItemKind::Module(item)); 301 self.push_item(current_module, attrs, RawItemKind::Module(item));
@@ -307,12 +303,10 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> {
307 } 303 }
308 304
309 if let Some(item_list) = module.item_list() { 305 if let Some(item_list) = module.item_list() {
310 let attr_path = extract_mod_path_attribute(&module);
311 let item = self.raw_items.modules.alloc(ModuleData::Definition { 306 let item = self.raw_items.modules.alloc(ModuleData::Definition {
312 name, 307 name,
313 ast_id, 308 ast_id,
314 items: Vec::new(), 309 items: Vec::new(),
315 attr_path,
316 is_macro_use, 310 is_macro_use,
317 }); 311 });
318 self.process_module(Some(item), item_list); 312 self.process_module(Some(item), item_list);
@@ -423,16 +417,3 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> {
423 Attr::from_attrs_owner(self.file_id, item, self.db) 417 Attr::from_attrs_owner(self.file_id, item, self.db)
424 } 418 }
425} 419}
426
427fn extract_mod_path_attribute(module: &ast::Module) -> Option<SmolStr> {
428 module.attrs().into_iter().find_map(|attr| {
429 attr.as_simple_key_value().and_then(|(name, value)| {
430 let is_path = name == "path";
431 if is_path {
432 Some(value)
433 } else {
434 None
435 }
436 })
437 })
438}