diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_scope.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 23 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/path_resolution.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir_def/src/per_ns.rs | 22 | ||||
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir_def/src/visibility.rs | 16 |
7 files changed, 51 insertions, 64 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 88c4a1216..fc3a028e0 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -543,7 +543,7 @@ where | |||
543 | }; | 543 | }; |
544 | self.body.item_scope.define_def(def); | 544 | self.body.item_scope.define_def(def); |
545 | if let Some(name) = name { | 545 | if let Some(name) = name { |
546 | let vis = crate::visibility::ResolvedVisibility::Public; // FIXME determine correctly | 546 | let vis = crate::visibility::Visibility::Public; // FIXME determine correctly |
547 | self.body | 547 | self.body |
548 | .item_scope | 548 | .item_scope |
549 | .push_res(name.as_name(), crate::per_ns::PerNs::from_def(def, vis)); | 549 | .push_res(name.as_name(), crate::per_ns::PerNs::from_def(def, vis)); |
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index db5f469c7..fe7bb9779 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs | |||
@@ -6,8 +6,8 @@ use once_cell::sync::Lazy; | |||
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | per_ns::PerNs, visibility::ResolvedVisibility, AdtId, BuiltinType, ImplId, MacroDefId, | 9 | per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, ImplId, MacroDefId, ModuleDefId, |
10 | ModuleDefId, TraitId, | 10 | TraitId, |
11 | }; | 11 | }; |
12 | 12 | ||
13 | #[derive(Debug, Default, PartialEq, Eq)] | 13 | #[derive(Debug, Default, PartialEq, Eq)] |
@@ -33,9 +33,7 @@ pub struct ItemScope { | |||
33 | static BUILTIN_SCOPE: Lazy<FxHashMap<Name, PerNs>> = Lazy::new(|| { | 33 | static BUILTIN_SCOPE: Lazy<FxHashMap<Name, PerNs>> = Lazy::new(|| { |
34 | BuiltinType::ALL | 34 | BuiltinType::ALL |
35 | .iter() | 35 | .iter() |
36 | .map(|(name, ty)| { | 36 | .map(|(name, ty)| (name.clone(), PerNs::types(ty.clone().into(), Visibility::Public))) |
37 | (name.clone(), PerNs::types(ty.clone().into(), ResolvedVisibility::Public)) | ||
38 | }) | ||
39 | .collect() | 37 | .collect() |
40 | }); | 38 | }); |
41 | 39 | ||
@@ -159,7 +157,7 @@ impl ItemScope { | |||
159 | } | 157 | } |
160 | 158 | ||
161 | impl PerNs { | 159 | impl PerNs { |
162 | pub(crate) fn from_def(def: ModuleDefId, v: ResolvedVisibility) -> PerNs { | 160 | pub(crate) fn from_def(def: ModuleDefId, v: Visibility) -> PerNs { |
163 | match def { | 161 | match def { |
164 | ModuleDefId::ModuleId(_) => PerNs::types(def, v), | 162 | ModuleDefId::ModuleId(_) => PerNs::types(def, v), |
165 | ModuleDefId::FunctionId(_) => PerNs::values(def, v), | 163 | ModuleDefId::FunctionId(_) => PerNs::values(def, v), |
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 { | |||
109 | struct DefCollector<'a, DB> { | 109 | struct 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) |
diff --git a/crates/ra_hir_def/src/per_ns.rs b/crates/ra_hir_def/src/per_ns.rs index 7637d8a37..6e435c8c1 100644 --- a/crates/ra_hir_def/src/per_ns.rs +++ b/crates/ra_hir_def/src/per_ns.rs | |||
@@ -5,13 +5,13 @@ | |||
5 | 5 | ||
6 | use hir_expand::MacroDefId; | 6 | use hir_expand::MacroDefId; |
7 | 7 | ||
8 | use crate::{visibility::ResolvedVisibility, ModuleDefId}; | 8 | use crate::{visibility::Visibility, ModuleDefId}; |
9 | 9 | ||
10 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] | 10 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
11 | pub struct PerNs { | 11 | pub struct PerNs { |
12 | pub types: Option<(ModuleDefId, ResolvedVisibility)>, | 12 | pub types: Option<(ModuleDefId, Visibility)>, |
13 | pub values: Option<(ModuleDefId, ResolvedVisibility)>, | 13 | pub values: Option<(ModuleDefId, Visibility)>, |
14 | pub macros: Option<(MacroDefId, ResolvedVisibility)>, | 14 | pub macros: Option<(MacroDefId, Visibility)>, |
15 | } | 15 | } |
16 | 16 | ||
17 | impl Default for PerNs { | 17 | impl Default for PerNs { |
@@ -25,19 +25,19 @@ impl PerNs { | |||
25 | PerNs { types: None, values: None, macros: None } | 25 | PerNs { types: None, values: None, macros: None } |
26 | } | 26 | } |
27 | 27 | ||
28 | pub fn values(t: ModuleDefId, v: ResolvedVisibility) -> PerNs { | 28 | pub fn values(t: ModuleDefId, v: Visibility) -> PerNs { |
29 | PerNs { types: None, values: Some((t, v)), macros: None } | 29 | PerNs { types: None, values: Some((t, v)), macros: None } |
30 | } | 30 | } |
31 | 31 | ||
32 | pub fn types(t: ModuleDefId, v: ResolvedVisibility) -> PerNs { | 32 | pub fn types(t: ModuleDefId, v: Visibility) -> PerNs { |
33 | PerNs { types: Some((t, v)), values: None, macros: None } | 33 | PerNs { types: Some((t, v)), values: None, macros: None } |
34 | } | 34 | } |
35 | 35 | ||
36 | pub fn both(types: ModuleDefId, values: ModuleDefId, v: ResolvedVisibility) -> PerNs { | 36 | pub fn both(types: ModuleDefId, values: ModuleDefId, v: Visibility) -> PerNs { |
37 | PerNs { types: Some((types, v)), values: Some((values, v)), macros: None } | 37 | PerNs { types: Some((types, v)), values: Some((values, v)), macros: None } |
38 | } | 38 | } |
39 | 39 | ||
40 | pub fn macros(macro_: MacroDefId, v: ResolvedVisibility) -> PerNs { | 40 | pub fn macros(macro_: MacroDefId, v: Visibility) -> PerNs { |
41 | PerNs { types: None, values: None, macros: Some((macro_, v)) } | 41 | PerNs { types: None, values: None, macros: Some((macro_, v)) } |
42 | } | 42 | } |
43 | 43 | ||
@@ -49,7 +49,7 @@ impl PerNs { | |||
49 | self.types.map(|it| it.0) | 49 | self.types.map(|it| it.0) |
50 | } | 50 | } |
51 | 51 | ||
52 | pub fn take_types_vis(self) -> Option<(ModuleDefId, ResolvedVisibility)> { | 52 | pub fn take_types_vis(self) -> Option<(ModuleDefId, Visibility)> { |
53 | self.types | 53 | self.types |
54 | } | 54 | } |
55 | 55 | ||
@@ -61,7 +61,7 @@ impl PerNs { | |||
61 | self.macros.map(|it| it.0) | 61 | self.macros.map(|it| it.0) |
62 | } | 62 | } |
63 | 63 | ||
64 | pub fn filter_visibility(self, mut f: impl FnMut(ResolvedVisibility) -> bool) -> PerNs { | 64 | pub fn filter_visibility(self, mut f: impl FnMut(Visibility) -> bool) -> PerNs { |
65 | PerNs { | 65 | PerNs { |
66 | types: self.types.filter(|(_, v)| f(*v)), | 66 | types: self.types.filter(|(_, v)| f(*v)), |
67 | values: self.values.filter(|(_, v)| f(*v)), | 67 | values: self.values.filter(|(_, v)| f(*v)), |
@@ -69,7 +69,7 @@ impl PerNs { | |||
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | pub fn with_visibility(self, vis: ResolvedVisibility) -> PerNs { | 72 | pub fn with_visibility(self, vis: Visibility) -> PerNs { |
73 | PerNs { | 73 | PerNs { |
74 | types: self.types.map(|(it, _)| (it, vis)), | 74 | types: self.types.map(|(it, _)| (it, vis)), |
75 | values: self.values.map(|(it, _)| (it, vis)), | 75 | values: self.values.map(|(it, _)| (it, vis)), |
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index 8e7a83ffe..43dc751d9 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -19,7 +19,7 @@ use crate::{ | |||
19 | nameres::CrateDefMap, | 19 | nameres::CrateDefMap, |
20 | path::{ModPath, PathKind}, | 20 | path::{ModPath, PathKind}, |
21 | per_ns::PerNs, | 21 | per_ns::PerNs, |
22 | visibility::{RawVisibility, ResolvedVisibility}, | 22 | visibility::{RawVisibility, Visibility}, |
23 | AdtId, AssocContainerId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, | 23 | AdtId, AssocContainerId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, |
24 | FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, | 24 | FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, |
25 | StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId, | 25 | StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId, |
@@ -236,7 +236,7 @@ impl Resolver { | |||
236 | &self, | 236 | &self, |
237 | db: &impl DefDatabase, | 237 | db: &impl DefDatabase, |
238 | visibility: &RawVisibility, | 238 | visibility: &RawVisibility, |
239 | ) -> Option<ResolvedVisibility> { | 239 | ) -> Option<Visibility> { |
240 | match visibility { | 240 | match visibility { |
241 | RawVisibility::Module(_) => { | 241 | RawVisibility::Module(_) => { |
242 | let (item_map, module) = match self.module() { | 242 | let (item_map, module) = match self.module() { |
@@ -245,7 +245,7 @@ impl Resolver { | |||
245 | }; | 245 | }; |
246 | item_map.resolve_visibility(db, module, visibility) | 246 | item_map.resolve_visibility(db, module, visibility) |
247 | } | 247 | } |
248 | RawVisibility::Public => Some(ResolvedVisibility::Public), | 248 | RawVisibility::Public => Some(Visibility::Public), |
249 | } | 249 | } |
250 | } | 250 | } |
251 | 251 | ||
@@ -466,16 +466,10 @@ impl Scope { | |||
466 | f(name.clone(), ScopeDef::PerNs(def)); | 466 | f(name.clone(), ScopeDef::PerNs(def)); |
467 | }); | 467 | }); |
468 | m.crate_def_map[m.module_id].scope.legacy_macros().for_each(|(name, macro_)| { | 468 | m.crate_def_map[m.module_id].scope.legacy_macros().for_each(|(name, macro_)| { |
469 | f( | 469 | f(name.clone(), ScopeDef::PerNs(PerNs::macros(macro_, Visibility::Public))); |
470 | name.clone(), | ||
471 | ScopeDef::PerNs(PerNs::macros(macro_, ResolvedVisibility::Public)), | ||
472 | ); | ||
473 | }); | 470 | }); |
474 | m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { | 471 | m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { |
475 | f( | 472 | f(name.clone(), ScopeDef::PerNs(PerNs::types(def.into(), Visibility::Public))); |
476 | name.clone(), | ||
477 | ScopeDef::PerNs(PerNs::types(def.into(), ResolvedVisibility::Public)), | ||
478 | ); | ||
479 | }); | 473 | }); |
480 | if let Some(prelude) = m.crate_def_map.prelude { | 474 | if let Some(prelude) = m.crate_def_map.prelude { |
481 | let prelude_def_map = db.crate_def_map(prelude.krate); | 475 | let prelude_def_map = db.crate_def_map(prelude.krate); |
diff --git a/crates/ra_hir_def/src/visibility.rs b/crates/ra_hir_def/src/visibility.rs index b11e9bc52..e4c25ab7d 100644 --- a/crates/ra_hir_def/src/visibility.rs +++ b/crates/ra_hir_def/src/visibility.rs | |||
@@ -109,26 +109,26 @@ impl RawVisibility { | |||
109 | &self, | 109 | &self, |
110 | db: &impl DefDatabase, | 110 | db: &impl DefDatabase, |
111 | resolver: &crate::resolver::Resolver, | 111 | resolver: &crate::resolver::Resolver, |
112 | ) -> ResolvedVisibility { | 112 | ) -> Visibility { |
113 | // we fall back to public visibility (i.e. fail open) if the path can't be resolved | 113 | // we fall back to public visibility (i.e. fail open) if the path can't be resolved |
114 | resolver.resolve_visibility(db, self).unwrap_or(ResolvedVisibility::Public) | 114 | resolver.resolve_visibility(db, self).unwrap_or(Visibility::Public) |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | /// Visibility of an item, with the path resolved. | 118 | /// Visibility of an item, with the path resolved. |
119 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] | 119 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
120 | pub enum ResolvedVisibility { | 120 | pub enum Visibility { |
121 | /// Visibility is restricted to a certain module. | 121 | /// Visibility is restricted to a certain module. |
122 | Module(ModuleId), | 122 | Module(ModuleId), |
123 | /// Visibility is unrestricted. | 123 | /// Visibility is unrestricted. |
124 | Public, | 124 | Public, |
125 | } | 125 | } |
126 | 126 | ||
127 | impl ResolvedVisibility { | 127 | impl Visibility { |
128 | pub fn visible_from(self, db: &impl DefDatabase, from_module: ModuleId) -> bool { | 128 | pub fn visible_from(self, db: &impl DefDatabase, from_module: ModuleId) -> bool { |
129 | let to_module = match self { | 129 | let to_module = match self { |
130 | ResolvedVisibility::Module(m) => m, | 130 | Visibility::Module(m) => m, |
131 | ResolvedVisibility::Public => return true, | 131 | Visibility::Public => return true, |
132 | }; | 132 | }; |
133 | // if they're not in the same crate, it can't be visible | 133 | // if they're not in the same crate, it can't be visible |
134 | if from_module.krate != to_module.krate { | 134 | if from_module.krate != to_module.krate { |
@@ -144,8 +144,8 @@ impl ResolvedVisibility { | |||
144 | from_module: crate::LocalModuleId, | 144 | from_module: crate::LocalModuleId, |
145 | ) -> bool { | 145 | ) -> bool { |
146 | let to_module = match self { | 146 | let to_module = match self { |
147 | ResolvedVisibility::Module(m) => m, | 147 | Visibility::Module(m) => m, |
148 | ResolvedVisibility::Public => return true, | 148 | Visibility::Public => return true, |
149 | }; | 149 | }; |
150 | // from_module needs to be a descendant of to_module | 150 | // from_module needs to be a descendant of to_module |
151 | let mut ancestors = std::iter::successors(Some(from_module), |m| { | 151 | let mut ancestors = std::iter::successors(Some(from_module), |m| { |