Rename Visibility -> RawVisibility

This commit is contained in:
Florian Diebold 2019-12-26 15:57:14 +01:00
parent 04e8eaa14b
commit e1a2961273
6 changed files with 40 additions and 40 deletions

View file

@ -14,7 +14,7 @@ use crate::{
generics::GenericParams,
lang_item::{LangItemTarget, LangItems},
nameres::{raw::RawItems, CrateDefMap},
visibility::Visibility,
visibility::RawVisibility,
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, VisibilityDefId,
@ -91,8 +91,8 @@ pub trait DefDatabase: InternDatabase + AstDatabase {
#[salsa::invoke(Attrs::attrs_query)]
fn attrs(&self, def: AttrDefId) -> Attrs;
#[salsa::invoke(Visibility::visibility_query)]
fn visibility(&self, def: VisibilityDefId) -> Visibility;
#[salsa::invoke(RawVisibility::visibility_query)]
fn visibility(&self, def: VisibilityDefId) -> RawVisibility;
#[salsa::invoke(LangItems::module_lang_items_query)]
fn module_lang_items(&self, module: ModuleId) -> Option<Arc<LangItems>>;

View file

@ -743,7 +743,7 @@ where
name: Name,
declaration: AstId<ast::Module>,
definition: Option<FileId>,
visibility: &crate::visibility::Visibility,
visibility: &crate::visibility::RawVisibility,
) -> LocalModuleId {
let vis = self
.def_collector

View file

@ -21,7 +21,7 @@ use crate::{
nameres::{BuiltinShadowMode, CrateDefMap},
path::{ModPath, PathKind},
per_ns::PerNs,
visibility::{ResolvedVisibility, Visibility},
visibility::{RawVisibility, ResolvedVisibility},
AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId,
};
@ -71,10 +71,10 @@ impl CrateDefMap {
&self,
db: &impl DefDatabase,
original_module: LocalModuleId,
visibility: &Visibility,
visibility: &RawVisibility,
) -> Option<ResolvedVisibility> {
match visibility {
Visibility::Module(path) => {
RawVisibility::Module(path) => {
let (result, remaining) =
self.resolve_path(db, original_module, &path, BuiltinShadowMode::Module);
if remaining.is_some() {
@ -89,7 +89,7 @@ impl CrateDefMap {
}
}
}
Visibility::Public => Some(ResolvedVisibility::Public),
RawVisibility::Public => Some(ResolvedVisibility::Public),
}
}

View file

@ -22,7 +22,7 @@ use ra_syntax::{
use test_utils::tested_by;
use crate::{
attr::Attrs, db::DefDatabase, path::ModPath, visibility::Visibility, FileAstId, HirFileId,
attr::Attrs, db::DefDatabase, path::ModPath, visibility::RawVisibility, FileAstId, HirFileId,
InFile,
};
@ -127,12 +127,12 @@ impl_arena_id!(Module);
pub(super) enum ModuleData {
Declaration {
name: Name,
visibility: Visibility,
visibility: RawVisibility,
ast_id: FileAstId<ast::Module>,
},
Definition {
name: Name,
visibility: Visibility,
visibility: RawVisibility,
ast_id: FileAstId<ast::Module>,
items: Vec<RawItem>,
},
@ -150,7 +150,7 @@ pub struct ImportData {
pub(super) is_prelude: bool,
pub(super) is_extern_crate: bool,
pub(super) is_macro_use: bool,
pub(super) visibility: Visibility,
pub(super) visibility: RawVisibility,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@ -161,7 +161,7 @@ impl_arena_id!(Def);
pub(super) struct DefData {
pub(super) name: Name,
pub(super) kind: DefKind,
pub(super) visibility: Visibility,
pub(super) visibility: RawVisibility,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
@ -232,7 +232,7 @@ impl RawItemsCollector {
fn add_item(&mut self, current_module: Option<Module>, item: ast::ModuleItem) {
let attrs = self.parse_attrs(&item);
let visibility = Visibility::from_ast_with_hygiene(item.visibility(), &self.hygiene);
let visibility = RawVisibility::from_ast_with_hygiene(item.visibility(), &self.hygiene);
let (kind, name) = match item {
ast::ModuleItem::Module(module) => {
self.add_module(current_module, module);
@ -292,7 +292,7 @@ impl RawItemsCollector {
None => return,
};
let attrs = self.parse_attrs(&module);
let visibility = Visibility::from_ast_with_hygiene(module.visibility(), &self.hygiene);
let visibility = RawVisibility::from_ast_with_hygiene(module.visibility(), &self.hygiene);
let ast_id = self.source_ast_id_map.ast_id(&module);
if module.has_semi() {
@ -320,7 +320,7 @@ impl RawItemsCollector {
// FIXME: cfg_attr
let is_prelude = use_item.has_atom_attr("prelude_import");
let attrs = self.parse_attrs(&use_item);
let visibility = Visibility::from_ast_with_hygiene(use_item.visibility(), &self.hygiene);
let visibility = RawVisibility::from_ast_with_hygiene(use_item.visibility(), &self.hygiene);
let mut buf = Vec::new();
ModPath::expand_use_item(
@ -352,7 +352,7 @@ impl RawItemsCollector {
if let Some(name_ref) = extern_crate.name_ref() {
let path = ModPath::from_name_ref(&name_ref);
let visibility =
Visibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene);
RawVisibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene);
let alias = extern_crate.alias().and_then(|a| a.name()).map(|it| it.as_name());
let attrs = self.parse_attrs(&extern_crate);
// FIXME: cfg_attr

View file

@ -19,7 +19,7 @@ use crate::{
nameres::CrateDefMap,
path::{ModPath, PathKind},
per_ns::PerNs,
visibility::{ResolvedVisibility, Visibility},
visibility::{RawVisibility, ResolvedVisibility},
AdtId, AssocContainerId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId,
FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId,
StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId,
@ -235,17 +235,17 @@ impl Resolver {
pub fn resolve_visibility(
&self,
db: &impl DefDatabase,
visibility: &Visibility,
visibility: &RawVisibility,
) -> Option<ResolvedVisibility> {
match visibility {
Visibility::Module(_) => {
RawVisibility::Module(_) => {
let (item_map, module) = match self.module() {
Some(it) => it,
None => return None,
};
item_map.resolve_visibility(db, module, visibility)
}
Visibility::Public => Some(ResolvedVisibility::Public),
RawVisibility::Public => Some(ResolvedVisibility::Public),
}
}

View file

@ -16,7 +16,7 @@ use crate::{
/// Visibility of an item, not yet resolved.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Visibility {
pub enum RawVisibility {
// FIXME: We could avoid the allocation in many cases by special-casing
// pub(crate), pub(super) and private. Alternatively, `ModPath` could be
// made to contain an Arc<[Segment]> instead of a Vec?
@ -27,16 +27,16 @@ pub enum Visibility {
Public,
}
impl Visibility {
pub(crate) fn visibility_query(db: &impl DefDatabase, def: VisibilityDefId) -> Visibility {
impl RawVisibility {
pub(crate) fn visibility_query(db: &impl DefDatabase, def: VisibilityDefId) -> RawVisibility {
match def {
VisibilityDefId::ModuleId(module) => {
let def_map = db.crate_def_map(module.krate);
let src = match def_map[module.local_id].declaration_source(db) {
Some(it) => it,
None => return Visibility::private(),
None => return RawVisibility::private(),
};
Visibility::from_ast(db, src.map(|it| it.visibility()))
RawVisibility::from_ast(db, src.map(|it| it.visibility()))
}
VisibilityDefId::StructFieldId(it) => {
let src = it.parent.child_source(db);
@ -49,9 +49,9 @@ impl Visibility {
Either::Right(record) => record.visibility(),
});
if vis_node.value.is_none() && is_enum {
Visibility::Public
RawVisibility::Public
} else {
Visibility::from_ast(db, vis_node)
RawVisibility::from_ast(db, vis_node)
}
}
VisibilityDefId::AdtId(it) => match it {
@ -67,41 +67,41 @@ impl Visibility {
}
}
fn private() -> Visibility {
fn private() -> RawVisibility {
let path = ModPath { kind: PathKind::Super(0), segments: Vec::new() };
Visibility::Module(Arc::new(path))
RawVisibility::Module(Arc::new(path))
}
fn from_ast(db: &impl DefDatabase, node: InFile<Option<ast::Visibility>>) -> Visibility {
fn from_ast(db: &impl DefDatabase, node: InFile<Option<ast::Visibility>>) -> RawVisibility {
Self::from_ast_with_hygiene(node.value, &Hygiene::new(db, node.file_id))
}
pub(crate) fn from_ast_with_hygiene(
node: Option<ast::Visibility>,
hygiene: &Hygiene,
) -> Visibility {
) -> RawVisibility {
let node = match node {
None => return Visibility::private(),
None => return RawVisibility::private(),
Some(node) => node,
};
match node.kind() {
ast::VisibilityKind::In(path) => {
let path = ModPath::from_src(path, hygiene);
let path = match path {
None => return Visibility::private(),
None => return RawVisibility::private(),
Some(path) => path,
};
Visibility::Module(Arc::new(path))
RawVisibility::Module(Arc::new(path))
}
ast::VisibilityKind::PubCrate => {
let path = ModPath { kind: PathKind::Crate, segments: Vec::new() };
Visibility::Module(Arc::new(path))
RawVisibility::Module(Arc::new(path))
}
ast::VisibilityKind::PubSuper => {
let path = ModPath { kind: PathKind::Super(1), segments: Vec::new() };
Visibility::Module(Arc::new(path))
RawVisibility::Module(Arc::new(path))
}
ast::VisibilityKind::Pub => Visibility::Public,
ast::VisibilityKind::Pub => RawVisibility::Public,
}
}
@ -156,11 +156,11 @@ impl ResolvedVisibility {
}
}
fn visibility_from_loc<T>(node: T, db: &impl DefDatabase) -> Visibility
fn visibility_from_loc<T>(node: T, db: &impl DefDatabase) -> RawVisibility
where
T: HasSource,
T::Value: ast::VisibilityOwner,
{
let src = node.source(db);
Visibility::from_ast(db, src.map(|n| n.visibility()))
RawVisibility::from_ast(db, src.map(|n| n.visibility()))
}