aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-12-26 14:57:14 +0000
committerFlorian Diebold <[email protected]>2019-12-26 15:23:40 +0000
commite1a2961273bdf7ef24c81f22fe86041a20812365 (patch)
tree1b2e3e4e76b121a43a6fc3fb1112668089c44abc /crates/ra_hir_def/src
parent04e8eaa14b11c432d43ad95f3766f8649da30347 (diff)
Rename Visibility -> RawVisibility
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/db.rs6
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs2
-rw-r--r--crates/ra_hir_def/src/nameres/path_resolution.rs8
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs18
-rw-r--r--crates/ra_hir_def/src/resolver.rs8
-rw-r--r--crates/ra_hir_def/src/visibility.rs38
6 files changed, 40 insertions, 40 deletions
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index 1761e2187..6bc0a8486 100644
--- a/crates/ra_hir_def/src/db.rs
+++ b/crates/ra_hir_def/src/db.rs
@@ -14,7 +14,7 @@ use crate::{
14 generics::GenericParams, 14 generics::GenericParams,
15 lang_item::{LangItemTarget, LangItems}, 15 lang_item::{LangItemTarget, LangItems},
16 nameres::{raw::RawItems, CrateDefMap}, 16 nameres::{raw::RawItems, CrateDefMap},
17 visibility::Visibility, 17 visibility::RawVisibility,
18 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, 18 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
19 GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, 19 GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
20 TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, VisibilityDefId, 20 TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, VisibilityDefId,
@@ -91,8 +91,8 @@ pub trait DefDatabase: InternDatabase + AstDatabase {
91 #[salsa::invoke(Attrs::attrs_query)] 91 #[salsa::invoke(Attrs::attrs_query)]
92 fn attrs(&self, def: AttrDefId) -> Attrs; 92 fn attrs(&self, def: AttrDefId) -> Attrs;
93 93
94 #[salsa::invoke(Visibility::visibility_query)] 94 #[salsa::invoke(RawVisibility::visibility_query)]
95 fn visibility(&self, def: VisibilityDefId) -> Visibility; 95 fn visibility(&self, def: VisibilityDefId) -> RawVisibility;
96 96
97 #[salsa::invoke(LangItems::module_lang_items_query)] 97 #[salsa::invoke(LangItems::module_lang_items_query)]
98 fn module_lang_items(&self, module: ModuleId) -> Option<Arc<LangItems>>; 98 fn module_lang_items(&self, module: ModuleId) -> Option<Arc<LangItems>>;
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index a80c4f8e9..f4678d145 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -743,7 +743,7 @@ where
743 name: Name, 743 name: Name,
744 declaration: AstId<ast::Module>, 744 declaration: AstId<ast::Module>,
745 definition: Option<FileId>, 745 definition: Option<FileId>,
746 visibility: &crate::visibility::Visibility, 746 visibility: &crate::visibility::RawVisibility,
747 ) -> LocalModuleId { 747 ) -> LocalModuleId {
748 let vis = self 748 let vis = self
749 .def_collector 749 .def_collector
diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs
index a56e3f08b..8a6256eee 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::{ResolvedVisibility, Visibility}, 24 visibility::{RawVisibility, ResolvedVisibility},
25 AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId, 25 AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId,
26}; 26};
27 27
@@ -71,10 +71,10 @@ impl CrateDefMap {
71 &self, 71 &self,
72 db: &impl DefDatabase, 72 db: &impl DefDatabase,
73 original_module: LocalModuleId, 73 original_module: LocalModuleId,
74 visibility: &Visibility, 74 visibility: &RawVisibility,
75 ) -> Option<ResolvedVisibility> { 75 ) -> Option<ResolvedVisibility> {
76 match visibility { 76 match visibility {
77 Visibility::Module(path) => { 77 RawVisibility::Module(path) => {
78 let (result, remaining) = 78 let (result, remaining) =
79 self.resolve_path(db, original_module, &path, BuiltinShadowMode::Module); 79 self.resolve_path(db, original_module, &path, BuiltinShadowMode::Module);
80 if remaining.is_some() { 80 if remaining.is_some() {
@@ -89,7 +89,7 @@ impl CrateDefMap {
89 } 89 }
90 } 90 }
91 } 91 }
92 Visibility::Public => Some(ResolvedVisibility::Public), 92 RawVisibility::Public => Some(ResolvedVisibility::Public),
93 } 93 }
94 } 94 }
95 95
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index 59f79f7cd..fac1169ef 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -22,7 +22,7 @@ use ra_syntax::{
22use test_utils::tested_by; 22use test_utils::tested_by;
23 23
24use crate::{ 24use crate::{
25 attr::Attrs, db::DefDatabase, path::ModPath, visibility::Visibility, FileAstId, HirFileId, 25 attr::Attrs, db::DefDatabase, path::ModPath, visibility::RawVisibility, FileAstId, HirFileId,
26 InFile, 26 InFile,
27}; 27};
28 28
@@ -127,12 +127,12 @@ impl_arena_id!(Module);
127pub(super) enum ModuleData { 127pub(super) enum ModuleData {
128 Declaration { 128 Declaration {
129 name: Name, 129 name: Name,
130 visibility: Visibility, 130 visibility: RawVisibility,
131 ast_id: FileAstId<ast::Module>, 131 ast_id: FileAstId<ast::Module>,
132 }, 132 },
133 Definition { 133 Definition {
134 name: Name, 134 name: Name,
135 visibility: Visibility, 135 visibility: RawVisibility,
136 ast_id: FileAstId<ast::Module>, 136 ast_id: FileAstId<ast::Module>,
137 items: Vec<RawItem>, 137 items: Vec<RawItem>,
138 }, 138 },
@@ -150,7 +150,7 @@ pub struct ImportData {
150 pub(super) is_prelude: bool, 150 pub(super) is_prelude: bool,
151 pub(super) is_extern_crate: bool, 151 pub(super) is_extern_crate: bool,
152 pub(super) is_macro_use: bool, 152 pub(super) is_macro_use: bool,
153 pub(super) visibility: Visibility, 153 pub(super) visibility: RawVisibility,
154} 154}
155 155
156#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 156#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -161,7 +161,7 @@ impl_arena_id!(Def);
161pub(super) struct DefData { 161pub(super) struct DefData {
162 pub(super) name: Name, 162 pub(super) name: Name,
163 pub(super) kind: DefKind, 163 pub(super) kind: DefKind,
164 pub(super) visibility: Visibility, 164 pub(super) visibility: RawVisibility,
165} 165}
166 166
167#[derive(Debug, PartialEq, Eq, Clone, Copy)] 167#[derive(Debug, PartialEq, Eq, Clone, Copy)]
@@ -232,7 +232,7 @@ impl RawItemsCollector {
232 232
233 fn add_item(&mut self, current_module: Option<Module>, item: ast::ModuleItem) { 233 fn add_item(&mut self, current_module: Option<Module>, item: ast::ModuleItem) {
234 let attrs = self.parse_attrs(&item); 234 let attrs = self.parse_attrs(&item);
235 let visibility = Visibility::from_ast_with_hygiene(item.visibility(), &self.hygiene); 235 let visibility = RawVisibility::from_ast_with_hygiene(item.visibility(), &self.hygiene);
236 let (kind, name) = match item { 236 let (kind, name) = match item {
237 ast::ModuleItem::Module(module) => { 237 ast::ModuleItem::Module(module) => {
238 self.add_module(current_module, module); 238 self.add_module(current_module, module);
@@ -292,7 +292,7 @@ impl RawItemsCollector {
292 None => return, 292 None => return,
293 }; 293 };
294 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); 295 let visibility = RawVisibility::from_ast_with_hygiene(module.visibility(), &self.hygiene);
296 296
297 let ast_id = self.source_ast_id_map.ast_id(&module); 297 let ast_id = self.source_ast_id_map.ast_id(&module);
298 if module.has_semi() { 298 if module.has_semi() {
@@ -320,7 +320,7 @@ impl RawItemsCollector {
320 // FIXME: cfg_attr 320 // FIXME: cfg_attr
321 let is_prelude = use_item.has_atom_attr("prelude_import"); 321 let is_prelude = use_item.has_atom_attr("prelude_import");
322 let attrs = self.parse_attrs(&use_item); 322 let attrs = self.parse_attrs(&use_item);
323 let visibility = Visibility::from_ast_with_hygiene(use_item.visibility(), &self.hygiene); 323 let visibility = RawVisibility::from_ast_with_hygiene(use_item.visibility(), &self.hygiene);
324 324
325 let mut buf = Vec::new(); 325 let mut buf = Vec::new();
326 ModPath::expand_use_item( 326 ModPath::expand_use_item(
@@ -352,7 +352,7 @@ impl RawItemsCollector {
352 if let Some(name_ref) = extern_crate.name_ref() { 352 if let Some(name_ref) = extern_crate.name_ref() {
353 let path = ModPath::from_name_ref(&name_ref); 353 let path = ModPath::from_name_ref(&name_ref);
354 let visibility = 354 let visibility =
355 Visibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene); 355 RawVisibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene);
356 let alias = extern_crate.alias().and_then(|a| a.name()).map(|it| it.as_name()); 356 let alias = extern_crate.alias().and_then(|a| a.name()).map(|it| it.as_name());
357 let attrs = self.parse_attrs(&extern_crate); 357 let attrs = self.parse_attrs(&extern_crate);
358 // FIXME: cfg_attr 358 // FIXME: cfg_attr
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index 950bf6c79..8e7a83ffe 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::{ResolvedVisibility, Visibility}, 22 visibility::{RawVisibility, ResolvedVisibility},
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,
@@ -235,17 +235,17 @@ impl Resolver {
235 pub fn resolve_visibility( 235 pub fn resolve_visibility(
236 &self, 236 &self,
237 db: &impl DefDatabase, 237 db: &impl DefDatabase,
238 visibility: &Visibility, 238 visibility: &RawVisibility,
239 ) -> Option<ResolvedVisibility> { 239 ) -> Option<ResolvedVisibility> {
240 match visibility { 240 match visibility {
241 Visibility::Module(_) => { 241 RawVisibility::Module(_) => {
242 let (item_map, module) = match self.module() { 242 let (item_map, module) = match self.module() {
243 Some(it) => it, 243 Some(it) => it,
244 None => return None, 244 None => return None,
245 }; 245 };
246 item_map.resolve_visibility(db, module, visibility) 246 item_map.resolve_visibility(db, module, visibility)
247 } 247 }
248 Visibility::Public => Some(ResolvedVisibility::Public), 248 RawVisibility::Public => Some(ResolvedVisibility::Public),
249 } 249 }
250 } 250 }
251 251
diff --git a/crates/ra_hir_def/src/visibility.rs b/crates/ra_hir_def/src/visibility.rs
index 990b2975c..b11e9bc52 100644
--- a/crates/ra_hir_def/src/visibility.rs
+++ b/crates/ra_hir_def/src/visibility.rs
@@ -16,7 +16,7 @@ use crate::{
16 16
17/// Visibility of an item, not yet resolved. 17/// Visibility of an item, not yet resolved.
18#[derive(Debug, Clone, PartialEq, Eq)] 18#[derive(Debug, Clone, PartialEq, Eq)]
19pub enum Visibility { 19pub enum RawVisibility {
20 // FIXME: We could avoid the allocation in many cases by special-casing 20 // FIXME: We could avoid the allocation in many cases by special-casing
21 // pub(crate), pub(super) and private. Alternatively, `ModPath` could be 21 // pub(crate), pub(super) and private. Alternatively, `ModPath` could be
22 // made to contain an Arc<[Segment]> instead of a Vec? 22 // made to contain an Arc<[Segment]> instead of a Vec?
@@ -27,16 +27,16 @@ pub enum Visibility {
27 Public, 27 Public,
28} 28}
29 29
30impl Visibility { 30impl RawVisibility {
31 pub(crate) fn visibility_query(db: &impl DefDatabase, def: VisibilityDefId) -> Visibility { 31 pub(crate) fn visibility_query(db: &impl DefDatabase, def: VisibilityDefId) -> RawVisibility {
32 match def { 32 match def {
33 VisibilityDefId::ModuleId(module) => { 33 VisibilityDefId::ModuleId(module) => {
34 let def_map = db.crate_def_map(module.krate); 34 let def_map = db.crate_def_map(module.krate);
35 let src = match def_map[module.local_id].declaration_source(db) { 35 let src = match def_map[module.local_id].declaration_source(db) {
36 Some(it) => it, 36 Some(it) => it,
37 None => return Visibility::private(), 37 None => return RawVisibility::private(),
38 }; 38 };
39 Visibility::from_ast(db, src.map(|it| it.visibility())) 39 RawVisibility::from_ast(db, src.map(|it| it.visibility()))
40 } 40 }
41 VisibilityDefId::StructFieldId(it) => { 41 VisibilityDefId::StructFieldId(it) => {
42 let src = it.parent.child_source(db); 42 let src = it.parent.child_source(db);
@@ -49,9 +49,9 @@ impl Visibility {
49 Either::Right(record) => record.visibility(), 49 Either::Right(record) => record.visibility(),
50 }); 50 });
51 if vis_node.value.is_none() && is_enum { 51 if vis_node.value.is_none() && is_enum {
52 Visibility::Public 52 RawVisibility::Public
53 } else { 53 } else {
54 Visibility::from_ast(db, vis_node) 54 RawVisibility::from_ast(db, vis_node)
55 } 55 }
56 } 56 }
57 VisibilityDefId::AdtId(it) => match it { 57 VisibilityDefId::AdtId(it) => match it {
@@ -67,41 +67,41 @@ impl Visibility {
67 } 67 }
68 } 68 }
69 69
70 fn private() -> Visibility { 70 fn private() -> RawVisibility {
71 let path = ModPath { kind: PathKind::Super(0), segments: Vec::new() }; 71 let path = ModPath { kind: PathKind::Super(0), segments: Vec::new() };
72 Visibility::Module(Arc::new(path)) 72 RawVisibility::Module(Arc::new(path))
73 } 73 }
74 74
75 fn from_ast(db: &impl DefDatabase, node: InFile<Option<ast::Visibility>>) -> Visibility { 75 fn from_ast(db: &impl DefDatabase, node: InFile<Option<ast::Visibility>>) -> RawVisibility {
76 Self::from_ast_with_hygiene(node.value, &Hygiene::new(db, node.file_id)) 76 Self::from_ast_with_hygiene(node.value, &Hygiene::new(db, node.file_id))
77 } 77 }
78 78
79 pub(crate) fn from_ast_with_hygiene( 79 pub(crate) fn from_ast_with_hygiene(
80 node: Option<ast::Visibility>, 80 node: Option<ast::Visibility>,
81 hygiene: &Hygiene, 81 hygiene: &Hygiene,
82 ) -> Visibility { 82 ) -> RawVisibility {
83 let node = match node { 83 let node = match node {
84 None => return Visibility::private(), 84 None => return RawVisibility::private(),
85 Some(node) => node, 85 Some(node) => node,
86 }; 86 };
87 match node.kind() { 87 match node.kind() {
88 ast::VisibilityKind::In(path) => { 88 ast::VisibilityKind::In(path) => {
89 let path = ModPath::from_src(path, hygiene); 89 let path = ModPath::from_src(path, hygiene);
90 let path = match path { 90 let path = match path {
91 None => return Visibility::private(), 91 None => return RawVisibility::private(),
92 Some(path) => path, 92 Some(path) => path,
93 }; 93 };
94 Visibility::Module(Arc::new(path)) 94 RawVisibility::Module(Arc::new(path))
95 } 95 }
96 ast::VisibilityKind::PubCrate => { 96 ast::VisibilityKind::PubCrate => {
97 let path = ModPath { kind: PathKind::Crate, segments: Vec::new() }; 97 let path = ModPath { kind: PathKind::Crate, segments: Vec::new() };
98 Visibility::Module(Arc::new(path)) 98 RawVisibility::Module(Arc::new(path))
99 } 99 }
100 ast::VisibilityKind::PubSuper => { 100 ast::VisibilityKind::PubSuper => {
101 let path = ModPath { kind: PathKind::Super(1), segments: Vec::new() }; 101 let path = ModPath { kind: PathKind::Super(1), segments: Vec::new() };
102 Visibility::Module(Arc::new(path)) 102 RawVisibility::Module(Arc::new(path))
103 } 103 }
104 ast::VisibilityKind::Pub => Visibility::Public, 104 ast::VisibilityKind::Pub => RawVisibility::Public,
105 } 105 }
106 } 106 }
107 107
@@ -156,11 +156,11 @@ impl ResolvedVisibility {
156 } 156 }
157} 157}
158 158
159fn visibility_from_loc<T>(node: T, db: &impl DefDatabase) -> Visibility 159fn visibility_from_loc<T>(node: T, db: &impl DefDatabase) -> RawVisibility
160where 160where
161 T: HasSource, 161 T: HasSource,
162 T::Value: ast::VisibilityOwner, 162 T::Value: ast::VisibilityOwner,
163{ 163{
164 let src = node.source(db); 164 let src = node.source(db);
165 Visibility::from_ast(db, src.map(|n| n.visibility())) 165 RawVisibility::from_ast(db, src.map(|n| n.visibility()))
166} 166}