diff options
author | uHOOCCOOHu <[email protected]> | 2019-09-07 17:37:54 +0100 |
---|---|---|
committer | uHOOCCOOHu <[email protected]> | 2019-09-08 18:34:53 +0100 |
commit | 92c07803cc0ce1d2008cc912f006d1cd66ff3f4a (patch) | |
tree | 2ab6e7c3f12be1d82e9da854e4ed091b7fd15877 /crates/ra_hir/src/nameres | |
parent | f7f7c2aff80f0870f0d71bf70075e3b5bf68994f (diff) |
Rename `textual_macro` -> `legacy_macro`
Add comments
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 37 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests/macros.rs | 2 |
2 files changed, 18 insertions, 21 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 10c32ffa1..09cda7656 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -146,22 +146,19 @@ where | |||
146 | self.def_map.exported_macros.insert(name.clone(), macro_id); | 146 | self.def_map.exported_macros.insert(name.clone(), macro_id); |
147 | } | 147 | } |
148 | self.update(module_id, None, &[(name.clone(), def)]); | 148 | self.update(module_id, None, &[(name.clone(), def)]); |
149 | self.define_textual_macro(module_id, name.clone(), macro_id); | 149 | self.define_legacy_macro(module_id, name.clone(), macro_id); |
150 | } | 150 | } |
151 | 151 | ||
152 | /// Define a macro in current textual scope. | 152 | /// Define a legacy textual scoped macro in module |
153 | /// | 153 | /// |
154 | /// We use a map `textual_macros` to store all textual macros visable per module. | 154 | /// We use a map `legacy_macros` to store all legacy textual scoped macros visable per module. |
155 | /// It will clone all macros from parent textual scope, whose definition is prior to | 155 | /// It will clone all macros from parent legacy scope, whose definition is prior to |
156 | /// the definition of current module. | 156 | /// the definition of current module. |
157 | /// And also, `macro_use` on a module will import all textual macros visable inside to | 157 | /// And also, `macro_use` on a module will import all legacy macros visable inside to |
158 | /// current textual scope, with possible shadowing. | 158 | /// current legacy scope, with possible shadowing. |
159 | fn define_textual_macro(&mut self, module_id: CrateModuleId, name: Name, macro_id: MacroDefId) { | 159 | fn define_legacy_macro(&mut self, module_id: CrateModuleId, name: Name, macro_id: MacroDefId) { |
160 | // Always shadowing | 160 | // Always shadowing |
161 | self.def_map.modules[module_id] | 161 | self.def_map.modules[module_id].scope.legacy_macros.insert(name, MacroDef { id: macro_id }); |
162 | .scope | ||
163 | .textual_macros | ||
164 | .insert(name, MacroDef { id: macro_id }); | ||
165 | } | 162 | } |
166 | 163 | ||
167 | /// Import macros from `#[macro_use] extern crate`. | 164 | /// Import macros from `#[macro_use] extern crate`. |
@@ -194,7 +191,7 @@ where | |||
194 | fn import_all_macros_exported(&mut self, current_module_id: CrateModuleId, module: Module) { | 191 | fn import_all_macros_exported(&mut self, current_module_id: CrateModuleId, module: Module) { |
195 | let item_map = self.db.crate_def_map(module.krate); | 192 | let item_map = self.db.crate_def_map(module.krate); |
196 | for (name, ¯o_id) in &item_map.exported_macros { | 193 | for (name, ¯o_id) in &item_map.exported_macros { |
197 | self.define_textual_macro(current_module_id, name.clone(), macro_id); | 194 | self.define_legacy_macro(current_module_id, name.clone(), macro_id); |
198 | } | 195 | } |
199 | } | 196 | } |
200 | 197 | ||
@@ -578,7 +575,7 @@ where | |||
578 | } | 575 | } |
579 | .collect(&*items); | 576 | .collect(&*items); |
580 | if *is_macro_use { | 577 | if *is_macro_use { |
581 | self.import_all_textual_macros(module_id); | 578 | self.import_all_legacy_macros(module_id); |
582 | } | 579 | } |
583 | } | 580 | } |
584 | // out of line module, resolve, parse and recurse | 581 | // out of line module, resolve, parse and recurse |
@@ -605,7 +602,7 @@ where | |||
605 | } | 602 | } |
606 | .collect(raw_items.items()); | 603 | .collect(raw_items.items()); |
607 | if *is_macro_use { | 604 | if *is_macro_use { |
608 | self.import_all_textual_macros(module_id); | 605 | self.import_all_legacy_macros(module_id); |
609 | } | 606 | } |
610 | } | 607 | } |
611 | Err(candidate) => self.def_collector.def_map.diagnostics.push( | 608 | Err(candidate) => self.def_collector.def_map.diagnostics.push( |
@@ -631,7 +628,7 @@ where | |||
631 | modules[res].parent = Some(self.module_id); | 628 | modules[res].parent = Some(self.module_id); |
632 | modules[res].declaration = Some(declaration); | 629 | modules[res].declaration = Some(declaration); |
633 | modules[res].definition = definition; | 630 | modules[res].definition = definition; |
634 | modules[res].scope.textual_macros = modules[self.module_id].scope.textual_macros.clone(); | 631 | modules[res].scope.legacy_macros = modules[self.module_id].scope.legacy_macros.clone(); |
635 | modules[self.module_id].children.insert(name.clone(), res); | 632 | modules[self.module_id].children.insert(name.clone(), res); |
636 | let resolution = Resolution { | 633 | let resolution = Resolution { |
637 | def: PerNs::types( | 634 | def: PerNs::types( |
@@ -685,10 +682,10 @@ where | |||
685 | 682 | ||
686 | let ast_id = mac.ast_id.with_file_id(self.file_id); | 683 | let ast_id = mac.ast_id.with_file_id(self.file_id); |
687 | 684 | ||
688 | // Case 2: try to resolve in textual scope and expand macro_rules, triggering | 685 | // Case 2: try to resolve in legacy scope and expand macro_rules, triggering |
689 | // recursive item collection. | 686 | // recursive item collection. |
690 | if let Some(macro_def) = mac.path.as_ident().and_then(|name| { | 687 | if let Some(macro_def) = mac.path.as_ident().and_then(|name| { |
691 | self.def_collector.def_map[self.module_id].scope.get_textual_macro(&name) | 688 | self.def_collector.def_map[self.module_id].scope.get_legacy_macro(&name) |
692 | }) { | 689 | }) { |
693 | let def = macro_def.id; | 690 | let def = macro_def.id; |
694 | let macro_call_id = MacroCallLoc { def, ast_id }.id(self.def_collector.db); | 691 | let macro_call_id = MacroCallLoc { def, ast_id }.id(self.def_collector.db); |
@@ -706,10 +703,10 @@ where | |||
706 | self.def_collector.unexpanded_macros.push((self.module_id, ast_id, path)); | 703 | self.def_collector.unexpanded_macros.push((self.module_id, ast_id, path)); |
707 | } | 704 | } |
708 | 705 | ||
709 | fn import_all_textual_macros(&mut self, module_id: CrateModuleId) { | 706 | fn import_all_legacy_macros(&mut self, module_id: CrateModuleId) { |
710 | let macros = self.def_collector.def_map[module_id].scope.textual_macros.clone(); | 707 | let macros = self.def_collector.def_map[module_id].scope.legacy_macros.clone(); |
711 | for (name, macro_) in macros { | 708 | for (name, macro_) in macros { |
712 | self.def_collector.define_textual_macro(self.module_id, name.clone(), macro_.id); | 709 | self.def_collector.define_legacy_macro(self.module_id, name.clone(), macro_.id); |
713 | } | 710 | } |
714 | } | 711 | } |
715 | } | 712 | } |
diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index a894c6836..21fab53e9 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs | |||
@@ -279,7 +279,7 @@ fn prelude_cycle() { | |||
279 | } | 279 | } |
280 | 280 | ||
281 | #[test] | 281 | #[test] |
282 | fn plain_macros_are_textual_scoped() { | 282 | fn plain_macros_are_legacy_textual_scoped() { |
283 | let map = def_map( | 283 | let map = def_map( |
284 | r#" | 284 | r#" |
285 | //- /main.rs | 285 | //- /main.rs |