aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-12-20 16:09:13 +0000
committerAleksey Kladov <[email protected]>2019-12-20 16:12:20 +0000
commit7a862f0d47e8ae018d449a04c918ea3705785552 (patch)
tree48200c7e43dbd10f9a584c360019b4721ac46285
parentaf42cb5981a1f94116b1da8cfeedb6efdd5aeb01 (diff)
Make legacy macros private
-rw-r--r--crates/ra_hir_def/src/item_scope.rs10
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs10
-rw-r--r--crates/ra_hir_def/src/nameres/tests.rs19
-rw-r--r--crates/ra_hir_def/src/nameres/tests/incremental.rs4
4 files changed, 24 insertions, 19 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs
index f51e97ef9..6b9be8325 100644
--- a/crates/ra_hir_def/src/item_scope.rs
+++ b/crates/ra_hir_def/src/item_scope.rs
@@ -23,7 +23,7 @@ pub struct ItemScope {
23 /// Module scoped macros will be inserted into `items` instead of here. 23 /// Module scoped macros will be inserted into `items` instead of here.
24 // FIXME: Macro shadowing in one module is not properly handled. Non-item place macros will 24 // FIXME: Macro shadowing in one module is not properly handled. Non-item place macros will
25 // be all resolved to the last one defined if shadowing happens. 25 // be all resolved to the last one defined if shadowing happens.
26 pub(crate) legacy_macros: FxHashMap<Name, MacroDefId>, 26 legacy_macros: FxHashMap<Name, MacroDefId>,
27} 27}
28 28
29static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| { 29static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| {
@@ -108,6 +108,10 @@ impl ItemScope {
108 self.impls.push(imp) 108 self.impls.push(imp)
109 } 109 }
110 110
111 pub(crate) fn define_legacy_macro(&mut self, name: Name, mac: MacroDefId) {
112 self.legacy_macros.insert(name, mac);
113 }
114
111 pub(crate) fn push_res( 115 pub(crate) fn push_res(
112 &mut self, 116 &mut self,
113 name: Name, 117 name: Name,
@@ -146,6 +150,10 @@ impl ItemScope {
146 pub(crate) fn collect_resolutions(&self) -> Vec<(Name, Resolution)> { 150 pub(crate) fn collect_resolutions(&self) -> Vec<(Name, Resolution)> {
147 self.items.iter().map(|(name, res)| (name.clone(), res.clone())).collect() 151 self.items.iter().map(|(name, res)| (name.clone(), res.clone())).collect()
148 } 152 }
153
154 pub(crate) fn collect_legacy_macros(&self) -> FxHashMap<Name, MacroDefId> {
155 self.legacy_macros.clone()
156 }
149} 157}
150 158
151#[derive(Debug, Clone, PartialEq, Eq, Default)] 159#[derive(Debug, Clone, PartialEq, Eq, Default)]
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index b064ccc9c..8b641d8b5 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -231,9 +231,9 @@ where
231 /// the definition of current module. 231 /// the definition of current module.
232 /// And also, `macro_use` on a module will import all legacy macros visible inside to 232 /// And also, `macro_use` on a module will import all legacy macros visible inside to
233 /// current legacy scope, with possible shadowing. 233 /// current legacy scope, with possible shadowing.
234 fn define_legacy_macro(&mut self, module_id: LocalModuleId, name: Name, macro_: MacroDefId) { 234 fn define_legacy_macro(&mut self, module_id: LocalModuleId, name: Name, mac: MacroDefId) {
235 // Always shadowing 235 // Always shadowing
236 self.def_map.modules[module_id].scope.legacy_macros.insert(name, macro_); 236 self.def_map.modules[module_id].scope.define_legacy_macro(name, mac);
237 } 237 }
238 238
239 /// Import macros from `#[macro_use] extern crate`. 239 /// Import macros from `#[macro_use] extern crate`.
@@ -711,7 +711,9 @@ where
711 let res = modules.alloc(ModuleData::default()); 711 let res = modules.alloc(ModuleData::default());
712 modules[res].parent = Some(self.module_id); 712 modules[res].parent = Some(self.module_id);
713 modules[res].origin = ModuleOrigin::not_sure_file(definition, declaration); 713 modules[res].origin = ModuleOrigin::not_sure_file(definition, declaration);
714 modules[res].scope.legacy_macros = modules[self.module_id].scope.legacy_macros.clone(); 714 for (name, mac) in modules[self.module_id].scope.collect_legacy_macros() {
715 modules[res].scope.define_legacy_macro(name, mac)
716 }
715 modules[self.module_id].children.insert(name.clone(), res); 717 modules[self.module_id].children.insert(name.clone(), res);
716 let resolution = Resolution { 718 let resolution = Resolution {
717 def: PerNs::types( 719 def: PerNs::types(
@@ -875,7 +877,7 @@ where
875 } 877 }
876 878
877 fn import_all_legacy_macros(&mut self, module_id: LocalModuleId) { 879 fn import_all_legacy_macros(&mut self, module_id: LocalModuleId) {
878 let macros = self.def_collector.def_map[module_id].scope.legacy_macros.clone(); 880 let macros = self.def_collector.def_map[module_id].scope.collect_legacy_macros();
879 for (name, macro_) in macros { 881 for (name, macro_) in macros {
880 self.def_collector.define_legacy_macro(self.module_id, name.clone(), macro_); 882 self.def_collector.define_legacy_macro(self.module_id, name.clone(), macro_);
881 } 883 }
diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs
index 61cdd768e..4e968bcc8 100644
--- a/crates/ra_hir_def/src/nameres/tests.rs
+++ b/crates/ra_hir_def/src/nameres/tests.rs
@@ -32,27 +32,22 @@ fn render_crate_def_map(map: &CrateDefMap) -> String {
32 *buf += path; 32 *buf += path;
33 *buf += "\n"; 33 *buf += "\n";
34 34
35 let mut entries = map.modules[module] 35 let mut entries = map.modules[module].scope.collect_resolutions();
36 .scope 36 entries.sort_by_key(|(name, _)| name.clone());
37 .items
38 .iter()
39 .map(|(name, res)| (name, res.def))
40 .collect::<Vec<_>>();
41 entries.sort_by_key(|(name, _)| *name);
42 37
43 for (name, res) in entries { 38 for (name, res) in entries {
44 *buf += &format!("{}:", name); 39 *buf += &format!("{}:", name);
45 40
46 if res.types.is_some() { 41 if res.def.types.is_some() {
47 *buf += " t"; 42 *buf += " t";
48 } 43 }
49 if res.values.is_some() { 44 if res.def.values.is_some() {
50 *buf += " v"; 45 *buf += " v";
51 } 46 }
52 if res.macros.is_some() { 47 if res.def.macros.is_some() {
53 *buf += " m"; 48 *buf += " m";
54 } 49 }
55 if res.is_none() { 50 if res.def.is_none() {
56 *buf += " _"; 51 *buf += " _";
57 } 52 }
58 53
@@ -587,6 +582,6 @@ mod b {
587 ⋮T: v 582 ⋮T: v
588 583
589 ⋮crate::a 584 ⋮crate::a
590 ⋮T: t v 585 ⋮T: t v
591"###); 586"###);
592} 587}
diff --git a/crates/ra_hir_def/src/nameres/tests/incremental.rs b/crates/ra_hir_def/src/nameres/tests/incremental.rs
index 903a22771..ef2e9435c 100644
--- a/crates/ra_hir_def/src/nameres/tests/incremental.rs
+++ b/crates/ra_hir_def/src/nameres/tests/incremental.rs
@@ -116,7 +116,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
116 let events = db.log_executed(|| { 116 let events = db.log_executed(|| {
117 let crate_def_map = db.crate_def_map(krate); 117 let crate_def_map = db.crate_def_map(krate);
118 let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); 118 let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
119 assert_eq!(module_data.scope.items.len(), 1); 119 assert_eq!(module_data.scope.collect_resolutions().len(), 1);
120 }); 120 });
121 assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) 121 assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
122 } 122 }
@@ -126,7 +126,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
126 let events = db.log_executed(|| { 126 let events = db.log_executed(|| {
127 let crate_def_map = db.crate_def_map(krate); 127 let crate_def_map = db.crate_def_map(krate);
128 let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); 128 let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
129 assert_eq!(module_data.scope.items.len(), 1); 129 assert_eq!(module_data.scope.collect_resolutions().len(), 1);
130 }); 130 });
131 assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) 131 assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
132 } 132 }