aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/item_scope.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-09-18 16:50:04 +0100
committerJonas Schievink <[email protected]>2020-09-18 16:50:04 +0100
commitbaab72e611fa985c2e62e964f3a48ad31367220f (patch)
tree278514b9e672529c43f20410fce7ce49b3d0ba89 /crates/hir_def/src/item_scope.rs
parent069045015c4b400754632c505f6ef19e32f9a4db (diff)
Reduce visibility of non-proc-macros
proc-macro crates only export proc-macros, but currently other items are also considered public (and show up in completion)
Diffstat (limited to 'crates/hir_def/src/item_scope.rs')
-rw-r--r--crates/hir_def/src/item_scope.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/crates/hir_def/src/item_scope.rs b/crates/hir_def/src/item_scope.rs
index f1e9dfd5b..99820c275 100644
--- a/crates/hir_def/src/item_scope.rs
+++ b/crates/hir_def/src/item_scope.rs
@@ -5,10 +5,12 @@ use std::collections::hash_map::Entry;
5 5
6use base_db::CrateId; 6use base_db::CrateId;
7use hir_expand::name::Name; 7use hir_expand::name::Name;
8use hir_expand::MacroDefKind;
8use once_cell::sync::Lazy; 9use once_cell::sync::Lazy;
9use rustc_hash::{FxHashMap, FxHashSet}; 10use rustc_hash::{FxHashMap, FxHashSet};
10use test_utils::mark; 11use test_utils::mark;
11 12
13use crate::ModuleId;
12use crate::{ 14use crate::{
13 db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, HasModule, ImplId, 15 db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, HasModule, ImplId,
14 LocalModuleId, Lookup, MacroDefId, ModuleDefId, TraitId, 16 LocalModuleId, Lookup, MacroDefId, ModuleDefId, TraitId,
@@ -265,6 +267,29 @@ impl ItemScope {
265 pub(crate) fn collect_legacy_macros(&self) -> FxHashMap<Name, MacroDefId> { 267 pub(crate) fn collect_legacy_macros(&self) -> FxHashMap<Name, MacroDefId> {
266 self.legacy_macros.clone() 268 self.legacy_macros.clone()
267 } 269 }
270
271 /// Marks everything that is not a procedural macro as private to `this_module`.
272 pub(crate) fn censor_non_proc_macros(&mut self, this_module: ModuleId) {
273 for vis in self
274 .types
275 .values_mut()
276 .chain(self.values.values_mut())
277 .map(|(_, v)| v)
278 .chain(self.unnamed_trait_imports.values_mut())
279 {
280 *vis = Visibility::Module(this_module);
281 }
282
283 for (mac, vis) in self.macros.values_mut() {
284 if let MacroDefKind::ProcMacro(_) = mac.kind {
285 // FIXME: Technically this is insufficient since reexports of proc macros are also
286 // forbidden. Practically nobody does that.
287 continue;
288 }
289
290 *vis = Visibility::Module(this_module);
291 }
292 }
268} 293}
269 294
270impl PerNs { 295impl PerNs {