aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-07-19 08:43:01 +0100
committerAleksey Kladov <[email protected]>2019-07-19 11:16:25 +0100
commite2b28f5bb8043e92b10f6a40696131007fc9dfe2 (patch)
treec14306038e386d71ddc894d63415bf8e9a94f7e8 /crates/ra_hir/src/nameres
parent7e02aa0efff228126ffc43e81e5e127e1b9e32dd (diff)
migrate ra_hir to the new rowan
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r--crates/ra_hir/src/nameres/raw.rs52
1 files changed, 26 insertions, 26 deletions
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs
index 46b2bef5b..8517f3c43 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir/src/nameres/raw.rs
@@ -3,7 +3,7 @@ use std::{ops::Index, sync::Arc};
3use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; 3use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{self, AttrsOwner, NameOwner}, 5 ast::{self, AttrsOwner, NameOwner},
6 AstNode, AstPtr, SmolStr, SourceFile, TreeArc, 6 AstNode, AstPtr, SmolStr, SourceFile,
7}; 7};
8use test_utils::tested_by; 8use test_utils::tested_by;
9 9
@@ -32,7 +32,7 @@ pub struct ImportSourceMap {
32} 32}
33 33
34type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; 34type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>;
35type ImportSource = Either<TreeArc<ast::UseTree>, TreeArc<ast::ExternCrateItem>>; 35type ImportSource = Either<ast::UseTree, ast::ExternCrateItem>;
36 36
37impl ImportSourcePtr { 37impl ImportSourcePtr {
38 fn to_node(self, file: &SourceFile) -> ImportSource { 38 fn to_node(self, file: &SourceFile) -> ImportSource {
@@ -50,11 +50,11 @@ impl ImportSourceMap {
50 50
51 pub(crate) fn get(&self, source: &ModuleSource, import: ImportId) -> ImportSource { 51 pub(crate) fn get(&self, source: &ModuleSource, import: ImportId) -> ImportSource {
52 let file = match source { 52 let file = match source {
53 ModuleSource::SourceFile(file) => &*file, 53 ModuleSource::SourceFile(file) => file.clone(),
54 ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), 54 ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(),
55 }; 55 };
56 56
57 self.map[import].to_node(file) 57 self.map[import].to_node(&file)
58 } 58 }
59} 59}
60 60
@@ -76,8 +76,8 @@ impl RawItems {
76 source_map: ImportSourceMap::default(), 76 source_map: ImportSourceMap::default(),
77 }; 77 };
78 if let Some(node) = db.parse_or_expand(file_id) { 78 if let Some(node) = db.parse_or_expand(file_id) {
79 if let Some(source_file) = ast::SourceFile::cast(&node) { 79 if let Some(source_file) = ast::SourceFile::cast(node) {
80 collector.process_module(None, &*source_file); 80 collector.process_module(None, source_file);
81 } 81 }
82 } 82 }
83 (Arc::new(collector.raw_items), Arc::new(collector.source_map)) 83 (Arc::new(collector.raw_items), Arc::new(collector.source_map))
@@ -188,7 +188,7 @@ struct RawItemsCollector {
188} 188}
189 189
190impl RawItemsCollector { 190impl RawItemsCollector {
191 fn process_module(&mut self, current_module: Option<Module>, body: &impl ast::ModuleItemOwner) { 191 fn process_module(&mut self, current_module: Option<Module>, body: impl ast::ModuleItemOwner) {
192 for item_or_macro in body.items_with_macros() { 192 for item_or_macro in body.items_with_macros() {
193 match item_or_macro { 193 match item_or_macro {
194 ast::ItemOrMacro::Macro(m) => self.add_macro(current_module, m), 194 ast::ItemOrMacro::Macro(m) => self.add_macro(current_module, m),
@@ -197,7 +197,7 @@ impl RawItemsCollector {
197 } 197 }
198 } 198 }
199 199
200 fn add_item(&mut self, current_module: Option<Module>, item: &ast::ModuleItem) { 200 fn add_item(&mut self, current_module: Option<Module>, item: ast::ModuleItem) {
201 let (kind, name) = match item.kind() { 201 let (kind, name) = match item.kind() {
202 ast::ModuleItemKind::Module(module) => { 202 ast::ModuleItemKind::Module(module) => {
203 self.add_module(current_module, module); 203 self.add_module(current_module, module);
@@ -216,7 +216,7 @@ impl RawItemsCollector {
216 return; 216 return;
217 } 217 }
218 ast::ModuleItemKind::StructDef(it) => { 218 ast::ModuleItemKind::StructDef(it) => {
219 let id = self.source_ast_id_map.ast_id(it); 219 let id = self.source_ast_id_map.ast_id(&it);
220 let name = it.name(); 220 let name = it.name();
221 if it.is_union() { 221 if it.is_union() {
222 (DefKind::Union(id), name) 222 (DefKind::Union(id), name)
@@ -225,22 +225,22 @@ impl RawItemsCollector {
225 } 225 }
226 } 226 }
227 ast::ModuleItemKind::EnumDef(it) => { 227 ast::ModuleItemKind::EnumDef(it) => {
228 (DefKind::Enum(self.source_ast_id_map.ast_id(it)), it.name()) 228 (DefKind::Enum(self.source_ast_id_map.ast_id(&it)), it.name())
229 } 229 }
230 ast::ModuleItemKind::FnDef(it) => { 230 ast::ModuleItemKind::FnDef(it) => {
231 (DefKind::Function(self.source_ast_id_map.ast_id(it)), it.name()) 231 (DefKind::Function(self.source_ast_id_map.ast_id(&it)), it.name())
232 } 232 }
233 ast::ModuleItemKind::TraitDef(it) => { 233 ast::ModuleItemKind::TraitDef(it) => {
234 (DefKind::Trait(self.source_ast_id_map.ast_id(it)), it.name()) 234 (DefKind::Trait(self.source_ast_id_map.ast_id(&it)), it.name())
235 } 235 }
236 ast::ModuleItemKind::TypeAliasDef(it) => { 236 ast::ModuleItemKind::TypeAliasDef(it) => {
237 (DefKind::TypeAlias(self.source_ast_id_map.ast_id(it)), it.name()) 237 (DefKind::TypeAlias(self.source_ast_id_map.ast_id(&it)), it.name())
238 } 238 }
239 ast::ModuleItemKind::ConstDef(it) => { 239 ast::ModuleItemKind::ConstDef(it) => {
240 (DefKind::Const(self.source_ast_id_map.ast_id(it)), it.name()) 240 (DefKind::Const(self.source_ast_id_map.ast_id(&it)), it.name())
241 } 241 }
242 ast::ModuleItemKind::StaticDef(it) => { 242 ast::ModuleItemKind::StaticDef(it) => {
243 (DefKind::Static(self.source_ast_id_map.ast_id(it)), it.name()) 243 (DefKind::Static(self.source_ast_id_map.ast_id(&it)), it.name())
244 } 244 }
245 }; 245 };
246 if let Some(name) = name { 246 if let Some(name) = name {
@@ -250,14 +250,14 @@ impl RawItemsCollector {
250 } 250 }
251 } 251 }
252 252
253 fn add_module(&mut self, current_module: Option<Module>, module: &ast::Module) { 253 fn add_module(&mut self, current_module: Option<Module>, module: ast::Module) {
254 let name = match module.name() { 254 let name = match module.name() {
255 Some(it) => it.as_name(), 255 Some(it) => it.as_name(),
256 None => return, 256 None => return,
257 }; 257 };
258 258
259 let attr_path = extract_mod_path_attribute(module); 259 let attr_path = extract_mod_path_attribute(&module);
260 let ast_id = self.source_ast_id_map.ast_id(module); 260 let ast_id = self.source_ast_id_map.ast_id(&module);
261 if module.has_semi() { 261 if module.has_semi() {
262 let item = 262 let item =
263 self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id, attr_path }); 263 self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id, attr_path });
@@ -278,10 +278,10 @@ impl RawItemsCollector {
278 tested_by!(name_res_works_for_broken_modules); 278 tested_by!(name_res_works_for_broken_modules);
279 } 279 }
280 280
281 fn add_use_item(&mut self, current_module: Option<Module>, use_item: &ast::UseItem) { 281 fn add_use_item(&mut self, current_module: Option<Module>, use_item: ast::UseItem) {
282 let is_prelude = use_item.has_atom_attr("prelude_import"); 282 let is_prelude = use_item.has_atom_attr("prelude_import");
283 283
284 Path::expand_use_item(use_item, |path, use_tree, is_glob, alias| { 284 Path::expand_use_item(&use_item, |path, use_tree, is_glob, alias| {
285 let import_data = 285 let import_data =
286 ImportData { path, alias, is_glob, is_prelude, is_extern_crate: false }; 286 ImportData { path, alias, is_glob, is_prelude, is_extern_crate: false };
287 self.push_import(current_module, import_data, Either::A(AstPtr::new(use_tree))); 287 self.push_import(current_module, import_data, Either::A(AstPtr::new(use_tree)));
@@ -291,11 +291,11 @@ impl RawItemsCollector {
291 fn add_extern_crate_item( 291 fn add_extern_crate_item(
292 &mut self, 292 &mut self,
293 current_module: Option<Module>, 293 current_module: Option<Module>,
294 extern_crate: &ast::ExternCrateItem, 294 extern_crate: ast::ExternCrateItem,
295 ) { 295 ) {
296 if let Some(name_ref) = extern_crate.name_ref() { 296 if let Some(name_ref) = extern_crate.name_ref() {
297 let path = Path::from_name_ref(name_ref); 297 let path = Path::from_name_ref(&name_ref);
298 let alias = extern_crate.alias().and_then(|a| a.name()).map(AsName::as_name); 298 let alias = extern_crate.alias().and_then(|a| a.name()).map(|it| it.as_name());
299 let import_data = ImportData { 299 let import_data = ImportData {
300 path, 300 path,
301 alias, 301 alias,
@@ -303,18 +303,18 @@ impl RawItemsCollector {
303 is_prelude: false, 303 is_prelude: false,
304 is_extern_crate: true, 304 is_extern_crate: true,
305 }; 305 };
306 self.push_import(current_module, import_data, Either::B(AstPtr::new(extern_crate))); 306 self.push_import(current_module, import_data, Either::B(AstPtr::new(&extern_crate)));
307 } 307 }
308 } 308 }
309 309
310 fn add_macro(&mut self, current_module: Option<Module>, m: &ast::MacroCall) { 310 fn add_macro(&mut self, current_module: Option<Module>, m: ast::MacroCall) {
311 let path = match m.path().and_then(Path::from_ast) { 311 let path = match m.path().and_then(Path::from_ast) {
312 Some(it) => it, 312 Some(it) => it,
313 _ => return, 313 _ => return,
314 }; 314 };
315 315
316 let name = m.name().map(|it| it.as_name()); 316 let name = m.name().map(|it| it.as_name());
317 let ast_id = self.source_ast_id_map.ast_id(m); 317 let ast_id = self.source_ast_id_map.ast_id(&m);
318 let export = m.has_atom_attr("macro_export"); 318 let export = m.has_atom_attr("macro_export");
319 let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export }); 319 let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export });
320 self.push_item(current_module, RawItem::Macro(m)); 320 self.push_item(current_module, RawItem::Macro(m));