aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-12-26 15:00:10 +0000
committerFlorian Diebold <[email protected]>2019-12-26 15:23:40 +0000
commit50ebff257dafe6e820f002241466ff4a98aa1f32 (patch)
tree5bfcf71964d649edb14b06394ff370c8ef556a5c /crates/ra_hir_def/src/nameres
parente1a2961273bdf7ef24c81f22fe86041a20812365 (diff)
Rename ResolvedVisibility -> Visibility
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs23
-rw-r--r--crates/ra_hir_def/src/nameres/path_resolution.rs26
2 files changed, 22 insertions, 27 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index f4678d145..63beaedc5 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -24,7 +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 visibility::Visibility,
28 AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, 28 AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
29 LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, 29 LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc,
30}; 30};
@@ -109,7 +109,7 @@ struct MacroDirective {
109struct DefCollector<'a, DB> { 109struct DefCollector<'a, DB> {
110 db: &'a DB, 110 db: &'a DB,
111 def_map: CrateDefMap, 111 def_map: CrateDefMap,
112 glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, ResolvedVisibility)>>, 112 glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>,
113 unresolved_imports: Vec<ImportDirective>, 113 unresolved_imports: Vec<ImportDirective>,
114 resolved_imports: Vec<ImportDirective>, 114 resolved_imports: Vec<ImportDirective>,
115 unexpanded_macros: Vec<MacroDirective>, 115 unexpanded_macros: Vec<MacroDirective>,
@@ -217,8 +217,8 @@ where
217 if export { 217 if export {
218 self.update( 218 self.update(
219 self.def_map.root, 219 self.def_map.root,
220 &[(name, PerNs::macros(macro_, ResolvedVisibility::Public))], 220 &[(name, PerNs::macros(macro_, Visibility::Public))],
221 ResolvedVisibility::Public, 221 Visibility::Public,
222 ); 222 );
223 } 223 }
224 } 224 }
@@ -358,7 +358,7 @@ where
358 let vis = self 358 let vis = self
359 .def_map 359 .def_map
360 .resolve_visibility(self.db, module_id, &directive.import.visibility) 360 .resolve_visibility(self.db, module_id, &directive.import.visibility)
361 .unwrap_or(ResolvedVisibility::Public); 361 .unwrap_or(Visibility::Public);
362 362
363 if import.is_glob { 363 if import.is_glob {
364 log::debug!("glob import: {:?}", import); 364 log::debug!("glob import: {:?}", import);
@@ -461,12 +461,7 @@ where
461 } 461 }
462 } 462 }
463 463
464 fn update( 464 fn update(&mut self, module_id: LocalModuleId, resolutions: &[(Name, PerNs)], vis: Visibility) {
465 &mut self,
466 module_id: LocalModuleId,
467 resolutions: &[(Name, PerNs)],
468 vis: ResolvedVisibility,
469 ) {
470 self.update_recursive(module_id, resolutions, vis, 0) 465 self.update_recursive(module_id, resolutions, vis, 0)
471 } 466 }
472 467
@@ -476,7 +471,7 @@ where
476 resolutions: &[(Name, PerNs)], 471 resolutions: &[(Name, PerNs)],
477 // All resolutions are imported with this visibility; the visibilies in 472 // All resolutions are imported with this visibility; the visibilies in
478 // the `PerNs` values are ignored and overwritten 473 // the `PerNs` values are ignored and overwritten
479 vis: ResolvedVisibility, 474 vis: Visibility,
480 depth: usize, 475 depth: usize,
481 ) { 476 ) {
482 if depth > 100 { 477 if depth > 100 {
@@ -749,7 +744,7 @@ where
749 .def_collector 744 .def_collector
750 .def_map 745 .def_map
751 .resolve_visibility(self.def_collector.db, self.module_id, visibility) 746 .resolve_visibility(self.def_collector.db, self.module_id, visibility)
752 .unwrap_or(ResolvedVisibility::Public); 747 .unwrap_or(Visibility::Public);
753 let modules = &mut self.def_collector.def_map.modules; 748 let modules = &mut self.def_collector.def_map.modules;
754 let res = modules.alloc(ModuleData::default()); 749 let res = modules.alloc(ModuleData::default());
755 modules[res].parent = Some(self.module_id); 750 modules[res].parent = Some(self.module_id);
@@ -825,7 +820,7 @@ where
825 .def_collector 820 .def_collector
826 .def_map 821 .def_map
827 .resolve_visibility(self.def_collector.db, self.module_id, vis) 822 .resolve_visibility(self.def_collector.db, self.module_id, vis)
828 .unwrap_or(ResolvedVisibility::Public); 823 .unwrap_or(Visibility::Public);
829 self.def_collector.update(self.module_id, &[(name, PerNs::from_def(def, vis))], vis) 824 self.def_collector.update(self.module_id, &[(name, PerNs::from_def(def, vis))], vis)
830 } 825 }
831 826
diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs
index 8a6256eee..fd6422d60 100644
--- a/crates/ra_hir_def/src/nameres/path_resolution.rs
+++ b/crates/ra_hir_def/src/nameres/path_resolution.rs
@@ -21,7 +21,7 @@ use crate::{
21 nameres::{BuiltinShadowMode, CrateDefMap}, 21 nameres::{BuiltinShadowMode, CrateDefMap},
22 path::{ModPath, PathKind}, 22 path::{ModPath, PathKind},
23 per_ns::PerNs, 23 per_ns::PerNs,
24 visibility::{RawVisibility, ResolvedVisibility}, 24 visibility::{RawVisibility, Visibility},
25 AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId, 25 AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId,
26}; 26};
27 27
@@ -64,7 +64,7 @@ impl CrateDefMap {
64 pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs { 64 pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs {
65 self.extern_prelude 65 self.extern_prelude
66 .get(name) 66 .get(name)
67 .map_or(PerNs::none(), |&it| PerNs::types(it, ResolvedVisibility::Public)) 67 .map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public))
68 } 68 }
69 69
70 pub(crate) fn resolve_visibility( 70 pub(crate) fn resolve_visibility(
@@ -72,7 +72,7 @@ impl CrateDefMap {
72 db: &impl DefDatabase, 72 db: &impl DefDatabase,
73 original_module: LocalModuleId, 73 original_module: LocalModuleId,
74 visibility: &RawVisibility, 74 visibility: &RawVisibility,
75 ) -> Option<ResolvedVisibility> { 75 ) -> Option<Visibility> {
76 match visibility { 76 match visibility {
77 RawVisibility::Module(path) => { 77 RawVisibility::Module(path) => {
78 let (result, remaining) = 78 let (result, remaining) =
@@ -82,14 +82,14 @@ impl CrateDefMap {
82 } 82 }
83 let types = result.take_types()?; 83 let types = result.take_types()?;
84 match types { 84 match types {
85 ModuleDefId::ModuleId(m) => Some(ResolvedVisibility::Module(m)), 85 ModuleDefId::ModuleId(m) => Some(Visibility::Module(m)),
86 _ => { 86 _ => {
87 // error: visibility needs to refer to module 87 // error: visibility needs to refer to module
88 None 88 None
89 } 89 }
90 } 90 }
91 } 91 }
92 RawVisibility::Public => Some(ResolvedVisibility::Public), 92 RawVisibility::Public => Some(Visibility::Public),
93 } 93 }
94 } 94 }
95 95
@@ -119,18 +119,18 @@ impl CrateDefMap {
119 tested_by!(macro_dollar_crate_self); 119 tested_by!(macro_dollar_crate_self);
120 PerNs::types( 120 PerNs::types(
121 ModuleId { krate: self.krate, local_id: self.root }.into(), 121 ModuleId { krate: self.krate, local_id: self.root }.into(),
122 ResolvedVisibility::Public, 122 Visibility::Public,
123 ) 123 )
124 } else { 124 } else {
125 let def_map = db.crate_def_map(krate); 125 let def_map = db.crate_def_map(krate);
126 let module = ModuleId { krate, local_id: def_map.root }; 126 let module = ModuleId { krate, local_id: def_map.root };
127 tested_by!(macro_dollar_crate_other); 127 tested_by!(macro_dollar_crate_other);
128 PerNs::types(module.into(), ResolvedVisibility::Public) 128 PerNs::types(module.into(), Visibility::Public)
129 } 129 }
130 } 130 }
131 PathKind::Crate => PerNs::types( 131 PathKind::Crate => PerNs::types(
132 ModuleId { krate: self.krate, local_id: self.root }.into(), 132 ModuleId { krate: self.krate, local_id: self.root }.into(),
133 ResolvedVisibility::Public, 133 Visibility::Public,
134 ), 134 ),
135 // plain import or absolute path in 2015: crate-relative with 135 // plain import or absolute path in 2015: crate-relative with
136 // fallback to extern prelude (with the simplification in 136 // fallback to extern prelude (with the simplification in
@@ -161,7 +161,7 @@ impl CrateDefMap {
161 if let Some(local_id) = m { 161 if let Some(local_id) = m {
162 PerNs::types( 162 PerNs::types(
163 ModuleId { krate: self.krate, local_id }.into(), 163 ModuleId { krate: self.krate, local_id }.into(),
164 ResolvedVisibility::Public, 164 Visibility::Public,
165 ) 165 )
166 } else { 166 } else {
167 log::debug!("super path in root module"); 167 log::debug!("super path in root module");
@@ -176,7 +176,7 @@ impl CrateDefMap {
176 }; 176 };
177 if let Some(def) = self.extern_prelude.get(&segment) { 177 if let Some(def) = self.extern_prelude.get(&segment) {
178 log::debug!("absolute path {:?} resolved to crate {:?}", path, def); 178 log::debug!("absolute path {:?} resolved to crate {:?}", path, def);
179 PerNs::types(*def, ResolvedVisibility::Public) 179 PerNs::types(*def, Visibility::Public)
180 } else { 180 } else {
181 return ResolvePathResult::empty(ReachedFixedPoint::No); // extern crate declarations can add to the extern prelude 181 return ResolvePathResult::empty(ReachedFixedPoint::No); // extern crate declarations can add to the extern prelude
182 } 182 }
@@ -225,7 +225,7 @@ impl CrateDefMap {
225 match enum_data.variant(&segment) { 225 match enum_data.variant(&segment) {
226 Some(local_id) => { 226 Some(local_id) => {
227 let variant = EnumVariantId { parent: e, local_id }; 227 let variant = EnumVariantId { parent: e, local_id };
228 PerNs::both(variant.into(), variant.into(), ResolvedVisibility::Public) 228 PerNs::both(variant.into(), variant.into(), Visibility::Public)
229 } 229 }
230 None => { 230 None => {
231 return ResolvePathResult::with( 231 return ResolvePathResult::with(
@@ -274,12 +274,12 @@ impl CrateDefMap {
274 let from_legacy_macro = self[module] 274 let from_legacy_macro = self[module]
275 .scope 275 .scope
276 .get_legacy_macro(name) 276 .get_legacy_macro(name)
277 .map_or_else(PerNs::none, |m| PerNs::macros(m, ResolvedVisibility::Public)); 277 .map_or_else(PerNs::none, |m| PerNs::macros(m, Visibility::Public));
278 let from_scope = self[module].scope.get(name, shadow); 278 let from_scope = self[module].scope.get(name, shadow);
279 let from_extern_prelude = self 279 let from_extern_prelude = self
280 .extern_prelude 280 .extern_prelude
281 .get(name) 281 .get(name)
282 .map_or(PerNs::none(), |&it| PerNs::types(it, ResolvedVisibility::Public)); 282 .map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public));
283 let from_prelude = self.resolve_in_prelude(db, name, shadow); 283 let from_prelude = self.resolve_in_prelude(db, name, shadow);
284 284
285 from_legacy_macro.or(from_scope).or(from_extern_prelude).or(from_prelude) 285 from_legacy_macro.or(from_scope).or(from_extern_prelude).or(from_prelude)