aboutsummaryrefslogtreecommitdiff
path: root/crates
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
parent79c90b5641d2934864c587380e4f050ab63ac029 (diff)
Keep track of visibility during def collection
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_def/src/body/lower.rs5
-rw-r--r--crates/ra_hir_def/src/item_scope.rs39
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs33
-rw-r--r--crates/ra_hir_def/src/nameres/path_resolution.rs45
-rw-r--r--crates/ra_hir_def/src/per_ns.rs42
-rw-r--r--crates/ra_hir_def/src/resolver.rs10
6 files changed, 120 insertions, 54 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 5323af097..88c4a1216 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -543,7 +543,10 @@ 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 self.body.item_scope.push_res(name.as_name(), def.into()); 546 let vis = crate::visibility::ResolvedVisibility::Public; // FIXME determine correctly
547 self.body
548 .item_scope
549 .push_res(name.as_name(), crate::per_ns::PerNs::from_def(def, vis));
547 } 550 }
548 } 551 }
549 } 552 }
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs
index b0288ee8d..d77f37f67 100644
--- a/crates/ra_hir_def/src/item_scope.rs
+++ b/crates/ra_hir_def/src/item_scope.rs
@@ -5,7 +5,10 @@ use hir_expand::name::Name;
5use once_cell::sync::Lazy; 5use once_cell::sync::Lazy;
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
7 7
8use crate::{per_ns::PerNs, AdtId, BuiltinType, ImplId, MacroDefId, ModuleDefId, TraitId}; 8use crate::{
9 per_ns::PerNs, visibility::ResolvedVisibility, AdtId, BuiltinType, ImplId, MacroDefId,
10 ModuleDefId, TraitId,
11};
9 12
10#[derive(Debug, Default, PartialEq, Eq)] 13#[derive(Debug, Default, PartialEq, Eq)]
11pub struct ItemScope { 14pub struct ItemScope {
@@ -30,7 +33,9 @@ pub struct ItemScope {
30static BUILTIN_SCOPE: Lazy<FxHashMap<Name, PerNs>> = Lazy::new(|| { 33static BUILTIN_SCOPE: Lazy<FxHashMap<Name, PerNs>> = Lazy::new(|| {
31 BuiltinType::ALL 34 BuiltinType::ALL
32 .iter() 35 .iter()
33 .map(|(name, ty)| (name.clone(), PerNs::types(ty.clone().into()))) 36 .map(|(name, ty)| {
37 (name.clone(), PerNs::types(ty.clone().into(), ResolvedVisibility::Public))
38 })
34 .collect() 39 .collect()
35}); 40});
36 41
@@ -144,29 +149,37 @@ impl ItemScope {
144 changed 149 changed
145 } 150 }
146 151
152 #[cfg(test)]
147 pub(crate) fn collect_resolutions(&self) -> Vec<(Name, PerNs)> { 153 pub(crate) fn collect_resolutions(&self) -> Vec<(Name, PerNs)> {
148 self.visible.iter().map(|(name, res)| (name.clone(), res.clone())).collect() 154 self.visible.iter().map(|(name, res)| (name.clone(), res.clone())).collect()
149 } 155 }
150 156
157 pub(crate) fn collect_resolutions_with_vis(
158 &self,
159 vis: ResolvedVisibility,
160 ) -> Vec<(Name, PerNs)> {
161 self.visible.iter().map(|(name, res)| (name.clone(), res.with_visibility(vis))).collect()
162 }
163
151 pub(crate) fn collect_legacy_macros(&self) -> FxHashMap<Name, MacroDefId> { 164 pub(crate) fn collect_legacy_macros(&self) -> FxHashMap<Name, MacroDefId> {
152 self.legacy_macros.clone() 165 self.legacy_macros.clone()
153 } 166 }
154} 167}
155 168
156impl From<ModuleDefId> for PerNs { 169impl PerNs {
157 fn from(def: ModuleDefId) -> PerNs { 170 pub(crate) fn from_def(def: ModuleDefId, v: ResolvedVisibility) -> PerNs {
158 match def { 171 match def {
159 ModuleDefId::ModuleId(_) => PerNs::types(def), 172 ModuleDefId::ModuleId(_) => PerNs::types(def, v),
160 ModuleDefId::FunctionId(_) => PerNs::values(def), 173 ModuleDefId::FunctionId(_) => PerNs::values(def, v),
161 ModuleDefId::AdtId(adt) => match adt { 174 ModuleDefId::AdtId(adt) => match adt {
162 AdtId::StructId(_) | AdtId::UnionId(_) => PerNs::both(def, def), 175 AdtId::StructId(_) | AdtId::UnionId(_) => PerNs::both(def, def, v),
163 AdtId::EnumId(_) => PerNs::types(def), 176 AdtId::EnumId(_) => PerNs::types(def, v),
164 }, 177 },
165 ModuleDefId::EnumVariantId(_) => PerNs::both(def, def), 178 ModuleDefId::EnumVariantId(_) => PerNs::both(def, def, v),
166 ModuleDefId::ConstId(_) | ModuleDefId::StaticId(_) => PerNs::values(def), 179 ModuleDefId::ConstId(_) | ModuleDefId::StaticId(_) => PerNs::values(def, v),
167 ModuleDefId::TraitId(_) => PerNs::types(def), 180 ModuleDefId::TraitId(_) => PerNs::types(def, v),
168 ModuleDefId::TypeAliasId(_) => PerNs::types(def), 181 ModuleDefId::TypeAliasId(_) => PerNs::types(def, v),
169 ModuleDefId::BuiltinType(_) => PerNs::types(def), 182 ModuleDefId::BuiltinType(_) => PerNs::types(def, v),
170 } 183 }
171 } 184 }
172} 185}
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) {
diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs
index d88076aa7..a56e3f08b 100644
--- a/crates/ra_hir_def/src/nameres/path_resolution.rs
+++ b/crates/ra_hir_def/src/nameres/path_resolution.rs
@@ -62,7 +62,9 @@ impl ResolvePathResult {
62 62
63impl CrateDefMap { 63impl 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.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)) 65 self.extern_prelude
66 .get(name)
67 .map_or(PerNs::none(), |&it| PerNs::types(it, ResolvedVisibility::Public))
66 } 68 }
67 69
68 pub(crate) fn resolve_visibility( 70 pub(crate) fn resolve_visibility(
@@ -115,17 +117,21 @@ impl CrateDefMap {
115 PathKind::DollarCrate(krate) => { 117 PathKind::DollarCrate(krate) => {
116 if krate == self.krate { 118 if krate == self.krate {
117 tested_by!(macro_dollar_crate_self); 119 tested_by!(macro_dollar_crate_self);
118 PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into()) 120 PerNs::types(
121 ModuleId { krate: self.krate, local_id: self.root }.into(),
122 ResolvedVisibility::Public,
123 )
119 } else { 124 } else {
120 let def_map = db.crate_def_map(krate); 125 let def_map = db.crate_def_map(krate);
121 let module = ModuleId { krate, local_id: def_map.root }; 126 let module = ModuleId { krate, local_id: def_map.root };
122 tested_by!(macro_dollar_crate_other); 127 tested_by!(macro_dollar_crate_other);
123 PerNs::types(module.into()) 128 PerNs::types(module.into(), ResolvedVisibility::Public)
124 } 129 }
125 } 130 }
126 PathKind::Crate => { 131 PathKind::Crate => PerNs::types(
127 PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into()) 132 ModuleId { krate: self.krate, local_id: self.root }.into(),
128 } 133 ResolvedVisibility::Public,
134 ),
129 // plain import or absolute path in 2015: crate-relative with 135 // plain import or absolute path in 2015: crate-relative with
130 // fallback to extern prelude (with the simplification in 136 // fallback to extern prelude (with the simplification in
131 // rust-lang/rust#57745) 137 // rust-lang/rust#57745)
@@ -153,7 +159,10 @@ impl CrateDefMap {
153 let m = successors(Some(original_module), |m| self.modules[*m].parent) 159 let m = successors(Some(original_module), |m| self.modules[*m].parent)
154 .nth(lvl as usize); 160 .nth(lvl as usize);
155 if let Some(local_id) = m { 161 if let Some(local_id) = m {
156 PerNs::types(ModuleId { krate: self.krate, local_id }.into()) 162 PerNs::types(
163 ModuleId { krate: self.krate, local_id }.into(),
164 ResolvedVisibility::Public,
165 )
157 } else { 166 } else {
158 log::debug!("super path in root module"); 167 log::debug!("super path in root module");
159 return ResolvePathResult::empty(ReachedFixedPoint::Yes); 168 return ResolvePathResult::empty(ReachedFixedPoint::Yes);
@@ -167,7 +176,7 @@ impl CrateDefMap {
167 }; 176 };
168 if let Some(def) = self.extern_prelude.get(&segment) { 177 if let Some(def) = self.extern_prelude.get(&segment) {
169 log::debug!("absolute path {:?} resolved to crate {:?}", path, def); 178 log::debug!("absolute path {:?} resolved to crate {:?}", path, def);
170 PerNs::types(*def) 179 PerNs::types(*def, ResolvedVisibility::Public)
171 } else { 180 } else {
172 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
173 } 182 }
@@ -175,7 +184,7 @@ impl CrateDefMap {
175 }; 184 };
176 185
177 for (i, segment) in segments { 186 for (i, segment) in segments {
178 let curr = match curr_per_ns.take_types() { 187 let (curr, vis) = match curr_per_ns.take_types_vis() {
179 Some(r) => r, 188 Some(r) => r,
180 None => { 189 None => {
181 // we still have path segments left, but the path so far 190 // we still have path segments left, but the path so far
@@ -216,11 +225,11 @@ impl CrateDefMap {
216 match enum_data.variant(&segment) { 225 match enum_data.variant(&segment) {
217 Some(local_id) => { 226 Some(local_id) => {
218 let variant = EnumVariantId { parent: e, local_id }; 227 let variant = EnumVariantId { parent: e, local_id };
219 PerNs::both(variant.into(), variant.into()) 228 PerNs::both(variant.into(), variant.into(), ResolvedVisibility::Public)
220 } 229 }
221 None => { 230 None => {
222 return ResolvePathResult::with( 231 return ResolvePathResult::with(
223 PerNs::types(e.into()), 232 PerNs::types(e.into(), vis),
224 ReachedFixedPoint::Yes, 233 ReachedFixedPoint::Yes,
225 Some(i), 234 Some(i),
226 Some(self.krate), 235 Some(self.krate),
@@ -238,7 +247,7 @@ impl CrateDefMap {
238 ); 247 );
239 248
240 return ResolvePathResult::with( 249 return ResolvePathResult::with(
241 PerNs::types(s), 250 PerNs::types(s, vis),
242 ReachedFixedPoint::Yes, 251 ReachedFixedPoint::Yes,
243 Some(i), 252 Some(i),
244 Some(self.krate), 253 Some(self.krate),
@@ -262,11 +271,15 @@ impl CrateDefMap {
262 // - current module / scope 271 // - current module / scope
263 // - extern prelude 272 // - extern prelude
264 // - std prelude 273 // - std prelude
265 let from_legacy_macro = 274 let from_legacy_macro = self[module]
266 self[module].scope.get_legacy_macro(name).map_or_else(PerNs::none, PerNs::macros); 275 .scope
276 .get_legacy_macro(name)
277 .map_or_else(PerNs::none, |m| PerNs::macros(m, ResolvedVisibility::Public));
267 let from_scope = self[module].scope.get(name, shadow); 278 let from_scope = self[module].scope.get(name, shadow);
268 let from_extern_prelude = 279 let from_extern_prelude = self
269 self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)); 280 .extern_prelude
281 .get(name)
282 .map_or(PerNs::none(), |&it| PerNs::types(it, ResolvedVisibility::Public));
270 let from_prelude = self.resolve_in_prelude(db, name, shadow); 283 let from_prelude = self.resolve_in_prelude(db, name, shadow);
271 284
272 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 3a5105028..16e61a6a5 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
6use hir_expand::MacroDefId; 6use hir_expand::MacroDefId;
7 7
8use crate::ModuleDefId; 8use crate::{visibility::ResolvedVisibility, ModuleDefId};
9 9
10#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] 10#[derive(Debug, Copy, Clone, PartialEq, Eq)]
11pub struct PerNs { 11pub struct PerNs {
12 pub types: Option<ModuleDefId>, 12 pub types: Option<(ModuleDefId, ResolvedVisibility)>,
13 pub values: Option<ModuleDefId>, 13 pub values: Option<(ModuleDefId, ResolvedVisibility)>,
14 pub macros: Option<MacroDefId>, 14 pub macros: Option<(MacroDefId, ResolvedVisibility)>,
15} 15}
16 16
17impl Default for PerNs { 17impl Default for PerNs {
@@ -25,20 +25,20 @@ 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) -> PerNs { 28 pub fn values(t: ModuleDefId, v: ResolvedVisibility) -> PerNs {
29 PerNs { types: None, values: Some(t), macros: None } 29 PerNs { types: None, values: Some((t, v)), macros: None }
30 } 30 }
31 31
32 pub fn types(t: ModuleDefId) -> PerNs { 32 pub fn types(t: ModuleDefId, v: ResolvedVisibility) -> PerNs {
33 PerNs { types: Some(t), 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) -> PerNs { 36 pub fn both(types: ModuleDefId, values: ModuleDefId, v: ResolvedVisibility) -> PerNs {
37 PerNs { types: Some(types), values: Some(values), macros: None } 37 PerNs { types: Some((types, v)), values: Some((values, v)), macros: None }
38 } 38 }
39 39
40 pub fn macros(macro_: MacroDefId) -> PerNs { 40 pub fn macros(macro_: MacroDefId, v: ResolvedVisibility) -> PerNs {
41 PerNs { types: None, values: None, macros: Some(macro_) } 41 PerNs { types: None, values: None, macros: Some((macro_, v)) }
42 } 42 }
43 43
44 pub fn is_none(&self) -> bool { 44 pub fn is_none(&self) -> bool {
@@ -46,15 +46,27 @@ impl PerNs {
46 } 46 }
47 47
48 pub fn take_types(self) -> Option<ModuleDefId> { 48 pub fn take_types(self) -> Option<ModuleDefId> {
49 self.types.map(|it| it.0)
50 }
51
52 pub fn take_types_vis(self) -> Option<(ModuleDefId, ResolvedVisibility)> {
49 self.types 53 self.types
50 } 54 }
51 55
52 pub fn take_values(self) -> Option<ModuleDefId> { 56 pub fn take_values(self) -> Option<ModuleDefId> {
53 self.values 57 self.values.map(|it| it.0)
54 } 58 }
55 59
56 pub fn take_macros(self) -> Option<MacroDefId> { 60 pub fn take_macros(self) -> Option<MacroDefId> {
57 self.macros 61 self.macros.map(|it| it.0)
62 }
63
64 pub fn with_visibility(self, vis: ResolvedVisibility) -> PerNs {
65 PerNs {
66 types: self.types.map(|(it, _)| (it, vis)),
67 values: self.values.map(|(it, _)| (it, vis)),
68 macros: self.macros.map(|(it, _)| (it, vis)),
69 }
58 } 70 }
59 71
60 pub fn or(self, other: PerNs) -> PerNs { 72 pub fn or(self, other: PerNs) -> PerNs {
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index b57dcf635..950bf6c79 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -466,10 +466,16 @@ 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(name.clone(), ScopeDef::PerNs(PerNs::macros(macro_))); 469 f(
470 name.clone(),
471 ScopeDef::PerNs(PerNs::macros(macro_, ResolvedVisibility::Public)),
472 );
470 }); 473 });
471 m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { 474 m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| {
472 f(name.clone(), ScopeDef::PerNs(PerNs::types(def.into()))); 475 f(
476 name.clone(),
477 ScopeDef::PerNs(PerNs::types(def.into(), ResolvedVisibility::Public)),
478 );
473 }); 479 });
474 if let Some(prelude) = m.crate_def_map.prelude { 480 if let Some(prelude) = m.crate_def_map.prelude {
475 let prelude_def_map = db.crate_def_map(prelude.krate); 481 let prelude_def_map = db.crate_def_map(prelude.krate);