diff options
Diffstat (limited to 'crates/ra_hir/src/nameres/collector.rs')
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index e6fd8632a..b5f02ab80 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -7,7 +7,7 @@ use ra_syntax::ast; | |||
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias, | 9 | Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias, |
10 | DefDatabase, HirFileId, Name, Path, SourceItemId, | 10 | DefDatabase, HirFileId, Name, Path, |
11 | KnownName, | 11 | KnownName, |
12 | nameres::{ | 12 | nameres::{ |
13 | Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, | 13 | Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, |
@@ -53,7 +53,7 @@ struct DefCollector<DB> { | |||
53 | def_map: CrateDefMap, | 53 | def_map: CrateDefMap, |
54 | glob_imports: FxHashMap<CrateModuleId, Vec<(CrateModuleId, raw::ImportId)>>, | 54 | glob_imports: FxHashMap<CrateModuleId, Vec<(CrateModuleId, raw::ImportId)>>, |
55 | unresolved_imports: Vec<(CrateModuleId, raw::ImportId, raw::ImportData)>, | 55 | unresolved_imports: Vec<(CrateModuleId, raw::ImportId, raw::ImportData)>, |
56 | unexpanded_macros: Vec<(CrateModuleId, SourceItemId, Path)>, | 56 | unexpanded_macros: Vec<(CrateModuleId, AstId<ast::MacroCall>, Path)>, |
57 | global_macro_scope: FxHashMap<Name, MacroDefId>, | 57 | global_macro_scope: FxHashMap<Name, MacroDefId>, |
58 | } | 58 | } |
59 | 59 | ||
@@ -295,7 +295,7 @@ where | |||
295 | let mut macros = std::mem::replace(&mut self.unexpanded_macros, Vec::new()); | 295 | let mut macros = std::mem::replace(&mut self.unexpanded_macros, Vec::new()); |
296 | let mut resolved = Vec::new(); | 296 | let mut resolved = Vec::new(); |
297 | let mut res = ReachedFixedPoint::Yes; | 297 | let mut res = ReachedFixedPoint::Yes; |
298 | macros.retain(|(module_id, source_item_id, path)| { | 298 | macros.retain(|(module_id, ast_id, path)| { |
299 | if path.segments.len() != 2 { | 299 | if path.segments.len() != 2 { |
300 | return true; | 300 | return true; |
301 | } | 301 | } |
@@ -311,8 +311,7 @@ where | |||
311 | res = ReachedFixedPoint::No; | 311 | res = ReachedFixedPoint::No; |
312 | let def_map = self.db.crate_def_map(krate); | 312 | let def_map = self.db.crate_def_map(krate); |
313 | if let Some(macro_id) = def_map.public_macros.get(&path.segments[1].name).cloned() { | 313 | if let Some(macro_id) = def_map.public_macros.get(&path.segments[1].name).cloned() { |
314 | let call_id = | 314 | let call_id = MacroCallLoc { def: macro_id, ast_id: *ast_id }.id(self.db); |
315 | MacroCallLoc { def: macro_id, source_item_id: *source_item_id }.id(self.db); | ||
316 | resolved.push((*module_id, call_id)); | 315 | resolved.push((*module_id, call_id)); |
317 | } | 316 | } |
318 | false | 317 | false |
@@ -456,34 +455,27 @@ where | |||
456 | // Case 1: macro rules, define a macro in crate-global mutable scope | 455 | // Case 1: macro rules, define a macro in crate-global mutable scope |
457 | if is_macro_rules(&mac.path) { | 456 | if is_macro_rules(&mac.path) { |
458 | if let Some(name) = &mac.name { | 457 | if let Some(name) = &mac.name { |
459 | let macro_id = MacroDefId::MacroByExample { | 458 | let macro_id = MacroDefId(mac.ast_id.with_file_id(self.file_id)); |
460 | source_item_id: mac.source_item_id.with_file_id(self.file_id), | ||
461 | }; | ||
462 | self.def_collector.define_macro(name.clone(), macro_id, mac.export) | 459 | self.def_collector.define_macro(name.clone(), macro_id, mac.export) |
463 | } | 460 | } |
464 | return; | 461 | return; |
465 | } | 462 | } |
466 | 463 | ||
467 | let source_item_id = SourceItemId { file_id: self.file_id, item_id: mac.source_item_id }; | 464 | let ast_id = mac.ast_id.with_file_id(self.file_id); |
468 | 465 | ||
469 | // Case 2: try to expand macro_rules from this crate, triggering | 466 | // Case 2: try to expand macro_rules from this crate, triggering |
470 | // recursive item collection. | 467 | // recursive item collection. |
471 | if let Some(¯o_id) = | 468 | if let Some(¯o_id) = |
472 | mac.path.as_ident().and_then(|name| self.def_collector.global_macro_scope.get(name)) | 469 | mac.path.as_ident().and_then(|name| self.def_collector.global_macro_scope.get(name)) |
473 | { | 470 | { |
474 | let macro_call_id = | 471 | let macro_call_id = MacroCallLoc { def: macro_id, ast_id }.id(self.def_collector.db); |
475 | MacroCallLoc { def: macro_id, source_item_id }.id(self.def_collector.db); | ||
476 | 472 | ||
477 | self.def_collector.collect_macro_expansion(self.module_id, macro_call_id); | 473 | self.def_collector.collect_macro_expansion(self.module_id, macro_call_id); |
478 | return; | 474 | return; |
479 | } | 475 | } |
480 | 476 | ||
481 | // Case 3: path to a macro from another crate, expand during name resolution | 477 | // Case 3: path to a macro from another crate, expand during name resolution |
482 | self.def_collector.unexpanded_macros.push(( | 478 | self.def_collector.unexpanded_macros.push((self.module_id, ast_id, mac.path.clone())) |
483 | self.module_id, | ||
484 | source_item_id, | ||
485 | mac.path.clone(), | ||
486 | )) | ||
487 | } | 479 | } |
488 | } | 480 | } |
489 | 481 | ||