Rename Visibility -> RawVisibility
This commit is contained in:
parent
04e8eaa14b
commit
e1a2961273
@ -14,7 +14,7 @@
|
||||
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>>;
|
||||
|
@ -743,7 +743,7 @@ fn push_child_module(
|
||||
name: Name,
|
||||
declaration: AstId<ast::Module>,
|
||||
definition: Option<FileId>,
|
||||
visibility: &crate::visibility::Visibility,
|
||||
visibility: &crate::visibility::RawVisibility,
|
||||
) -> LocalModuleId {
|
||||
let vis = self
|
||||
.def_collector
|
||||
|
@ -21,7 +21,7 @@
|
||||
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 @@ pub(crate) fn resolve_visibility(
|
||||
&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 @@ pub(crate) fn resolve_visibility(
|
||||
}
|
||||
}
|
||||
}
|
||||
Visibility::Public => Some(ResolvedVisibility::Public),
|
||||
RawVisibility::Public => Some(ResolvedVisibility::Public),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
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 @@ pub(super) enum RawItemKind {
|
||||
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 @@ pub struct ImportData {
|
||||
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 @@ fn process_module(&mut self, current_module: Option<Module>, body: impl ast::Mod
|
||||
|
||||
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 @@ fn add_module(&mut self, current_module: Option<Module>, module: ast::Module) {
|
||||
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 @@ fn add_use_item(&mut self, current_module: Option<Module>, use_item: ast::UseIte
|
||||
// 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 @@ fn add_extern_crate_item(
|
||||
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
|
||||
|
@ -19,7 +19,7 @@
|
||||
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 @@ pub fn resolve_path_in_type_ns_fully(
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
/// 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 @@ pub(crate) fn visibility_query(db: &impl DefDatabase, def: VisibilityDefId) -> V
|
||||
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 @@ pub(crate) fn visibility_query(db: &impl DefDatabase, def: VisibilityDefId) -> V
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ pub(crate) fn visible_from_def_map(
|
||||
}
|
||||
}
|
||||
|
||||
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()))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user