aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres/collector.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-12-25 14:00:10 +0000
committerFlorian Diebold <[email protected]>2019-12-26 15:23:40 +0000
commit8ac25f119eb45d425370d9f7f093bc206e6c4a9f (patch)
tree7a9bcbcb2c46a549baa7a411a99cd7c9eb39423d /crates/ra_hir_def/src/nameres/collector.rs
parent79c90b5641d2934864c587380e4f050ab63ac029 (diff)
Keep track of visibility during def collection
Diffstat (limited to 'crates/ra_hir_def/src/nameres/collector.rs')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs33
1 files changed, 26 insertions, 7 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index b9f40d3dd..5b8478037 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -24,6 +24,7 @@ use crate::{
24 }, 24 },
25 path::{ModPath, PathKind}, 25 path::{ModPath, PathKind},
26 per_ns::PerNs, 26 per_ns::PerNs,
27 visibility::ResolvedVisibility,
27 AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, 28 AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
28 LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, 29 LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc,
29}; 30};
@@ -214,7 +215,10 @@ where
214 // In Rust, `#[macro_export]` macros are unconditionally visible at the 215 // In Rust, `#[macro_export]` macros are unconditionally visible at the
215 // crate root, even if the parent modules is **not** visible. 216 // crate root, even if the parent modules is **not** visible.
216 if export { 217 if export {
217 self.update(self.def_map.root, &[(name, PerNs::macros(macro_))]); 218 self.update(
219 self.def_map.root,
220 &[(name, PerNs::macros(macro_, ResolvedVisibility::Public))],
221 );
218 } 222 }
219 } 223 }
220 224
@@ -351,6 +355,10 @@ where
351 let import_id = directive.import_id; 355 let import_id = directive.import_id;
352 let import = &directive.import; 356 let import = &directive.import;
353 let def = directive.status.namespaces(); 357 let def = directive.status.namespaces();
358 let vis = self
359 .def_map
360 .resolve_visibility(self.db, module_id, &directive.import.visibility)
361 .unwrap_or(ResolvedVisibility::Public);
354 362
355 if import.is_glob { 363 if import.is_glob {
356 log::debug!("glob import: {:?}", import); 364 log::debug!("glob import: {:?}", import);
@@ -365,8 +373,10 @@ where
365 let item_map = self.db.crate_def_map(m.krate); 373 let item_map = self.db.crate_def_map(m.krate);
366 let scope = &item_map[m.local_id].scope; 374 let scope = &item_map[m.local_id].scope;
367 375
376 // TODO: only use names we can see
377
368 // Module scoped macros is included 378 // Module scoped macros is included
369 let items = scope.collect_resolutions(); 379 let items = scope.collect_resolutions_with_vis(vis);
370 380
371 self.update(module_id, &items); 381 self.update(module_id, &items);
372 } else { 382 } else {
@@ -375,8 +385,10 @@ where
375 // additions 385 // additions
376 let scope = &self.def_map[m.local_id].scope; 386 let scope = &self.def_map[m.local_id].scope;
377 387
388 // TODO: only use names we can see
389
378 // Module scoped macros is included 390 // Module scoped macros is included
379 let items = scope.collect_resolutions(); 391 let items = scope.collect_resolutions_with_vis(vis);
380 392
381 self.update(module_id, &items); 393 self.update(module_id, &items);
382 // record the glob import in case we add further items 394 // record the glob import in case we add further items
@@ -396,7 +408,7 @@ where
396 .map(|(local_id, variant_data)| { 408 .map(|(local_id, variant_data)| {
397 let name = variant_data.name.clone(); 409 let name = variant_data.name.clone();
398 let variant = EnumVariantId { parent: e, local_id }; 410 let variant = EnumVariantId { parent: e, local_id };
399 let res = PerNs::both(variant.into(), variant.into()); 411 let res = PerNs::both(variant.into(), variant.into(), vis);
400 (name, res) 412 (name, res)
401 }) 413 })
402 .collect::<Vec<_>>(); 414 .collect::<Vec<_>>();
@@ -422,7 +434,7 @@ where
422 } 434 }
423 } 435 }
424 436
425 self.update(module_id, &[(name, def)]); 437 self.update(module_id, &[(name, def.with_visibility(vis))]);
426 } 438 }
427 None => tested_by!(bogus_paths), 439 None => tested_by!(bogus_paths),
428 } 440 }
@@ -701,8 +713,9 @@ where
701 modules[self.module_id].children.insert(name.clone(), res); 713 modules[self.module_id].children.insert(name.clone(), res);
702 let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: res }; 714 let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: res };
703 let def: ModuleDefId = module.into(); 715 let def: ModuleDefId = module.into();
716 let vis = ResolvedVisibility::Public; // TODO handle module visibility
704 self.def_collector.def_map.modules[self.module_id].scope.define_def(def); 717 self.def_collector.def_map.modules[self.module_id].scope.define_def(def);
705 self.def_collector.update(self.module_id, &[(name, def.into())]); 718 self.def_collector.update(self.module_id, &[(name, PerNs::from_def(def, vis))]);
706 res 719 res
707 } 720 }
708 721
@@ -716,6 +729,7 @@ where
716 729
717 let name = def.name.clone(); 730 let name = def.name.clone();
718 let container = ContainerId::ModuleId(module); 731 let container = ContainerId::ModuleId(module);
732 let vis = &def.visibility;
719 let def: ModuleDefId = match def.kind { 733 let def: ModuleDefId = match def.kind {
720 raw::DefKind::Function(ast_id) => FunctionLoc { 734 raw::DefKind::Function(ast_id) => FunctionLoc {
721 container: container.into(), 735 container: container.into(),
@@ -761,7 +775,12 @@ where
761 .into(), 775 .into(),
762 }; 776 };
763 self.def_collector.def_map.modules[self.module_id].scope.define_def(def); 777 self.def_collector.def_map.modules[self.module_id].scope.define_def(def);
764 self.def_collector.update(self.module_id, &[(name, def.into())]) 778 let vis = self
779 .def_collector
780 .def_map
781 .resolve_visibility(self.def_collector.db, self.module_id, vis)
782 .unwrap_or(ResolvedVisibility::Public);
783 self.def_collector.update(self.module_id, &[(name, PerNs::from_def(def, vis))])
765 } 784 }
766 785
767 fn collect_derives(&mut self, attrs: &Attrs, def: &raw::DefData) { 786 fn collect_derives(&mut self, attrs: &Attrs, def: &raw::DefData) {