diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/globs.rs | 3 |
3 files changed, 36 insertions, 11 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 51df44d2f..a80c4f8e9 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -677,9 +677,13 @@ where | |||
677 | let is_macro_use = attrs.by_key("macro_use").exists(); | 677 | let is_macro_use = attrs.by_key("macro_use").exists(); |
678 | match module { | 678 | match module { |
679 | // inline module, just recurse | 679 | // inline module, just recurse |
680 | raw::ModuleData::Definition { name, items, ast_id } => { | 680 | raw::ModuleData::Definition { name, visibility, items, ast_id } => { |
681 | let module_id = | 681 | let module_id = self.push_child_module( |
682 | self.push_child_module(name.clone(), AstId::new(self.file_id, *ast_id), None); | 682 | name.clone(), |
683 | AstId::new(self.file_id, *ast_id), | ||
684 | None, | ||
685 | &visibility, | ||
686 | ); | ||
683 | 687 | ||
684 | ModCollector { | 688 | ModCollector { |
685 | def_collector: &mut *self.def_collector, | 689 | def_collector: &mut *self.def_collector, |
@@ -694,7 +698,7 @@ where | |||
694 | } | 698 | } |
695 | } | 699 | } |
696 | // out of line module, resolve, parse and recurse | 700 | // out of line module, resolve, parse and recurse |
697 | raw::ModuleData::Declaration { name, ast_id } => { | 701 | raw::ModuleData::Declaration { name, visibility, ast_id } => { |
698 | let ast_id = AstId::new(self.file_id, *ast_id); | 702 | let ast_id = AstId::new(self.file_id, *ast_id); |
699 | match self.mod_dir.resolve_declaration( | 703 | match self.mod_dir.resolve_declaration( |
700 | self.def_collector.db, | 704 | self.def_collector.db, |
@@ -703,7 +707,12 @@ where | |||
703 | path_attr, | 707 | path_attr, |
704 | ) { | 708 | ) { |
705 | Ok((file_id, mod_dir)) => { | 709 | Ok((file_id, mod_dir)) => { |
706 | let module_id = self.push_child_module(name.clone(), ast_id, Some(file_id)); | 710 | let module_id = self.push_child_module( |
711 | name.clone(), | ||
712 | ast_id, | ||
713 | Some(file_id), | ||
714 | &visibility, | ||
715 | ); | ||
707 | let raw_items = self.def_collector.db.raw_items(file_id.into()); | 716 | let raw_items = self.def_collector.db.raw_items(file_id.into()); |
708 | ModCollector { | 717 | ModCollector { |
709 | def_collector: &mut *self.def_collector, | 718 | def_collector: &mut *self.def_collector, |
@@ -734,7 +743,13 @@ where | |||
734 | name: Name, | 743 | name: Name, |
735 | declaration: AstId<ast::Module>, | 744 | declaration: AstId<ast::Module>, |
736 | definition: Option<FileId>, | 745 | definition: Option<FileId>, |
746 | visibility: &crate::visibility::Visibility, | ||
737 | ) -> LocalModuleId { | 747 | ) -> LocalModuleId { |
748 | let vis = self | ||
749 | .def_collector | ||
750 | .def_map | ||
751 | .resolve_visibility(self.def_collector.db, self.module_id, visibility) | ||
752 | .unwrap_or(ResolvedVisibility::Public); | ||
738 | let modules = &mut self.def_collector.def_map.modules; | 753 | let modules = &mut self.def_collector.def_map.modules; |
739 | let res = modules.alloc(ModuleData::default()); | 754 | let res = modules.alloc(ModuleData::default()); |
740 | modules[res].parent = Some(self.module_id); | 755 | modules[res].parent = Some(self.module_id); |
@@ -745,7 +760,6 @@ where | |||
745 | modules[self.module_id].children.insert(name.clone(), res); | 760 | modules[self.module_id].children.insert(name.clone(), res); |
746 | let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: res }; | 761 | let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: res }; |
747 | let def: ModuleDefId = module.into(); | 762 | let def: ModuleDefId = module.into(); |
748 | let vis = ResolvedVisibility::Public; // TODO handle module visibility | ||
749 | self.def_collector.def_map.modules[self.module_id].scope.define_def(def); | 763 | self.def_collector.def_map.modules[self.module_id].scope.define_def(def); |
750 | self.def_collector.update(self.module_id, &[(name, PerNs::from_def(def, vis))], vis); | 764 | self.def_collector.update(self.module_id, &[(name, PerNs::from_def(def, vis))], vis); |
751 | res | 765 | res |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 9dabb5b6d..59f79f7cd 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -125,8 +125,17 @@ impl_arena_id!(Module); | |||
125 | 125 | ||
126 | #[derive(Debug, PartialEq, Eq)] | 126 | #[derive(Debug, PartialEq, Eq)] |
127 | pub(super) enum ModuleData { | 127 | pub(super) enum ModuleData { |
128 | Declaration { name: Name, ast_id: FileAstId<ast::Module> }, | 128 | Declaration { |
129 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, | 129 | name: Name, |
130 | visibility: Visibility, | ||
131 | ast_id: FileAstId<ast::Module>, | ||
132 | }, | ||
133 | Definition { | ||
134 | name: Name, | ||
135 | visibility: Visibility, | ||
136 | ast_id: FileAstId<ast::Module>, | ||
137 | items: Vec<RawItem>, | ||
138 | }, | ||
130 | } | 139 | } |
131 | 140 | ||
132 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 141 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -283,10 +292,12 @@ impl RawItemsCollector { | |||
283 | None => return, | 292 | None => return, |
284 | }; | 293 | }; |
285 | let attrs = self.parse_attrs(&module); | 294 | let attrs = self.parse_attrs(&module); |
295 | let visibility = Visibility::from_ast_with_hygiene(module.visibility(), &self.hygiene); | ||
286 | 296 | ||
287 | let ast_id = self.source_ast_id_map.ast_id(&module); | 297 | let ast_id = self.source_ast_id_map.ast_id(&module); |
288 | if module.has_semi() { | 298 | if module.has_semi() { |
289 | let item = self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id }); | 299 | let item = |
300 | self.raw_items.modules.alloc(ModuleData::Declaration { name, visibility, ast_id }); | ||
290 | self.push_item(current_module, attrs, RawItemKind::Module(item)); | 301 | self.push_item(current_module, attrs, RawItemKind::Module(item)); |
291 | return; | 302 | return; |
292 | } | 303 | } |
@@ -294,6 +305,7 @@ impl RawItemsCollector { | |||
294 | if let Some(item_list) = module.item_list() { | 305 | if let Some(item_list) = module.item_list() { |
295 | let item = self.raw_items.modules.alloc(ModuleData::Definition { | 306 | let item = self.raw_items.modules.alloc(ModuleData::Definition { |
296 | name, | 307 | name, |
308 | visibility, | ||
297 | ast_id, | 309 | ast_id, |
298 | items: Vec::new(), | 310 | items: Vec::new(), |
299 | }); | 311 | }); |
diff --git a/crates/ra_hir_def/src/nameres/tests/globs.rs b/crates/ra_hir_def/src/nameres/tests/globs.rs index 5f137d3a6..82d947b78 100644 --- a/crates/ra_hir_def/src/nameres/tests/globs.rs +++ b/crates/ra_hir_def/src/nameres/tests/globs.rs | |||
@@ -122,7 +122,7 @@ fn glob_privacy_2() { | |||
122 | use foo::bar::*; | 122 | use foo::bar::*; |
123 | 123 | ||
124 | //- /foo/mod.rs | 124 | //- /foo/mod.rs |
125 | pub mod bar; | 125 | mod bar; |
126 | fn Foo() {}; | 126 | fn Foo() {}; |
127 | pub struct Foo {}; | 127 | pub struct Foo {}; |
128 | 128 | ||
@@ -136,7 +136,6 @@ fn glob_privacy_2() { | |||
136 | crate | 136 | crate |
137 | Foo: t | 137 | Foo: t |
138 | PubCrateStruct: t v | 138 | PubCrateStruct: t v |
139 | bar: t | ||
140 | foo: t | 139 | foo: t |
141 | 140 | ||
142 | crate::foo | 141 | crate::foo |